<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
class pro_print_excel_new extends MY_Controller {
	
	function __construct()
	{
		parent::__construct();

		$this->secure_session();
	}

	function tenant_all()
	{

		$status_tenant='Tenant';
		$tanggal=get('tanggal');
		$x=0;

		$ls_sql	= " SELECT	*
					FROM	pro_tenant
					WHERE	UPPER(status_tenant) = 'TENANT' AND
							(UPPER(no_tenant) LIKE '%".strtoupper(post('keyword'))."%'
							OR UPPER(nama_tenant) LIKE '%".strtoupper(post('keyword'))."%'
							OR UPPER(no_toko) LIKE '%".strtoupper(post('keyword'))."%'
							OR UPPER(luas_tempat) LIKE '%".strtoupper(post('keyword'))."%'
							OR UPPER(lokasi_tempat) LIKE '%".strtoupper(post('keyword'))."%'
							OR UPPER(jenis_usaha) LIKE '%".strtoupper(post('keyword'))."%'
							OR UPPER(alamat_lengkap) LIKE '%".strtoupper(post('keyword'))."%'
							OR UPPER(status_anggota) LIKE '%".strtoupper(post('keyword'))."%'
							OR UPPER(no_anggota) LIKE '%".strtoupper(post('keyword'))."%'
							OR UPPER(no_id_card) LIKE '%".strtoupper(post('keyword'))."%'
							OR UPPER(no_telephone) LIKE '%".strtoupper(post('keyword'))."%'
							OR UPPER(no_handphone) LIKE '%".strtoupper(post('keyword'))."%'
							OR UPPER(status_tenant) LIKE '%".strtoupper(post('keyword'))."%'
							OR UPPER(no_kontrak) LIKE '%".strtoupper(post('keyword'))."%'
							OR UPPER(periode_awal_sewa) LIKE '%".strtoupper(post('keyword'))."%'
							OR UPPER(periode_akhir_sewa) LIKE '%".strtoupper(post('keyword'))."%'
							OR UPPER(jangka_waktu) LIKE '%".strtoupper(post('keyword'))."%'
							OR UPPER(harga_sewa) LIKE '%".strtoupper(post('keyword'))."%'
							OR UPPER(keterangan) LIKE '%".strtoupper(post('keyword'))."%')
					ORDER BY ".(post('sort')=='' ? 'id_lokasi' : post('sort'))." ".(post('order')=='' ? 'asc' : post('order')).",REGEXP_REPLACE(no_toko, '[0-9]', ''), TO_NUMBER(REGEXP_SUBSTR(no_toko, '[0-9]+'))";	
		
		$ls_sql2	= "	SELECT COUNT(1)
						FROM	pro_tenant
					    WHERE	UPPER(status_tenant) = 'TENANT' AND
							(UPPER(no_tenant) LIKE '%".strtoupper(post('keyword'))."%'
							OR UPPER(nama_tenant) LIKE '%".strtoupper(post('keyword'))."%'
							OR UPPER(no_toko) LIKE '%".strtoupper(post('keyword'))."%'
							OR UPPER(luas_tempat) LIKE '%".strtoupper(post('keyword'))."%'
							OR UPPER(lokasi_tempat) LIKE '%".strtoupper(post('keyword'))."%'
							OR UPPER(jenis_usaha) LIKE '%".strtoupper(post('keyword'))."%'
							OR UPPER(alamat_lengkap) LIKE '%".strtoupper(post('keyword'))."%'
							OR UPPER(status_anggota) LIKE '%".strtoupper(post('keyword'))."%'
							OR UPPER(no_anggota) LIKE '%".strtoupper(post('keyword'))."%'
							OR UPPER(no_id_card) LIKE '%".strtoupper(post('keyword'))."%'
							OR UPPER(no_telephone) LIKE '%".strtoupper(post('keyword'))."%'
							OR UPPER(no_handphone) LIKE '%".strtoupper(post('keyword'))."%'
							OR UPPER(status_tenant) LIKE '%".strtoupper(post('keyword'))."%'
							OR UPPER(no_kontrak) LIKE '%".strtoupper(post('keyword'))."%'
							OR UPPER(periode_awal_sewa) LIKE '%".strtoupper(post('keyword'))."%'
							OR UPPER(periode_akhir_sewa) LIKE '%".strtoupper(post('keyword'))."%'
							OR UPPER(jangka_waktu) LIKE '%".strtoupper(post('keyword'))."%'
							OR UPPER(harga_sewa) LIKE '%".strtoupper(post('keyword'))."%'
							OR UPPER(keterangan) LIKE '%".strtoupper(post('keyword'))."%')
							ORDER BY ".(post('sort')=='' ? 'no_tenant' : post('sort'))." ".(post('order')=='' ? 'asc' : post('order'));
		
		$total = $this->get_data($ls_sql2);

		$result = $this->db->query($ls_sql);

		$data_p = array(	'rows'=> $result->result_array(), 
								'total' => $total);

		$date = date('Y-m-d');

		//load our new PHPExcel library
		$this->load->library('excel');
		//activate worksheet number 1
		$this->excel->setActiveSheetIndex(0);
		//name the worksheet
		$this->excel->getActiveSheet()->setTitle("Data Tenant_".$date);

		

			
		if ($data_p) {

			$styleArrayBorder = array(
				'borders' => array(
					'allborders' => array(
					'style' => PHPExcel_Style_Border::BORDER_THIN
					)
				)
			);

			$this->excel->getActiveSheet()->setCellValue('B8', 'No Tenant');
			$this->excel->getActiveSheet()->setCellValue('C8', 'Nama Tenant');
			$this->excel->getActiveSheet()->setCellValue('D8', 'No Toko');
			$this->excel->getActiveSheet()->setCellValue('E8', 'Luas Tempat');
			$this->excel->getActiveSheet()->setCellValue('F8', 'Lokasi Tempat');
			$this->excel->getActiveSheet()->setCellValue('G8', 'Jenis Usaha');
			$this->excel->getActiveSheet()->setCellValue('H8', 'Alamat Lengkap');
			$this->excel->getActiveSheet()->setCellValue('I8', 'Staus Anggota');
			$this->excel->getActiveSheet()->setCellValue('J8', 'No Anggota');
			$this->excel->getActiveSheet()->setCellValue('K8', 'NO.ID Card');
			$this->excel->getActiveSheet()->setCellValue('L8', 'No Telephone');
			$this->excel->getActiveSheet()->setCellValue('M8', 'No Handphone');
			$this->excel->getActiveSheet()->setCellValue('N8', 'Status Tenant');
			$this->excel->getActiveSheet()->setCellValue('O8', 'No Kontrak');
			$this->excel->getActiveSheet()->setCellValue('P8', 'Periode Awal Sewa');
			$this->excel->getActiveSheet()->setCellValue('Q8', 'Periode Akhir Sewa');
			$this->excel->getActiveSheet()->setCellValue('R8', 'Jangka Waktu');
			$this->excel->getActiveSheet()->setCellValue('S8', 'Harga Sewa');
			$this->excel->getActiveSheet()->setCellValue('T8', 'Keterangan');
			
			$this->excel->getActiveSheet()->getStyle('B8:T8')->getFont()->setBold(true);
			$this->excel->getActiveSheet()->getStyle('B8:T8')->getFill()->applyFromArray(array('type' => PHPExcel_Style_Fill::FILL_SOLID,'startcolor' => array('rgb' => 'B2B2B2')));
			$this->excel->getActiveSheet()->getStyle('B8:T8')->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_CENTER);

			$x = 8;

			for($i=0;$i<=$data_p['total']-1;$i++){
				$x++;

				$rows = $data_p['rows'];
				$rows2 = $rows[$i];

				$this->excel->getActiveSheet()->setCellValue('B'.$x, $rows2['no_tenant']);
				$this->excel->getActiveSheet()->getStyle('B'.$x)->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
				$this->excel->getActiveSheet()->setCellValue('C'.$x, $rows2['nama_tenant']);
				$this->excel->getActiveSheet()->setCellValue('D'.$x, $rows2['no_toko']);
				$this->excel->getActiveSheet()->getStyle('D'.$x.':E'.$x)->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
				$this->excel->getActiveSheet()->setCellValue('E'.$x, $rows2['luas_tempat']);
				$this->excel->getActiveSheet()->setCellValue('F'.$x, $rows2['lokasi_tempat']);
				$this->excel->getActiveSheet()->getStyle('F'.$x)->getAlignment()->setWrapText(true);
				$this->excel->getActiveSheet()->setCellValue('G'.$x, $rows2['jenis_usaha']);
				$this->excel->getActiveSheet()->getStyle('G'.$x)->getAlignment()->setWrapText(true);
				$this->excel->getActiveSheet()->setCellValue('H'.$x, $rows2['alamat_lengkap']);
				$this->excel->getActiveSheet()->getStyle('H'.$x)->getAlignment()->setWrapText(true);
				$this->excel->getActiveSheet()->setCellValue('I'.$x, $rows2['status_anggota']);
				$this->excel->getActiveSheet()->setCellValue('J'.$x, $rows2['no_anggota']);
				$this->excel->getActiveSheet()->setCellValue('K'.$x, $rows2['no_id_card']);
				$this->excel->getActiveSheet()->setCellValue('L'.$x, $rows2['no_telephone']);
				$this->excel->getActiveSheet()->setCellValue('M'.$x, $rows2['no_handphone']);
				$this->excel->getActiveSheet()->getStyle('L'.$x.':M'.$x)->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_RIGHT);
				$this->excel->getActiveSheet()->setCellValue('N'.$x, $rows2['status_tenant']);
				$this->excel->getActiveSheet()->setCellValue('O'.$x, $rows2['no_kontrak']);
				$this->excel->getActiveSheet()->getStyle('O'.$x)->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_LEFT);
				$this->excel->getActiveSheet()->setCellValue('P'.$x, $rows2['periode_awal_sewa']);
				$this->excel->getActiveSheet()->setCellValue('Q'.$x, $rows2['periode_akhir_sewa']);
				$this->excel->getActiveSheet()->getStyle('P'.$x.':Q'.$x)->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
				$this->excel->getActiveSheet()->setCellValue('R'.$x, $rows2['jangka_waktu']);
				$this->excel->getActiveSheet()->setCellValue('S'.$x, $rows2['harga_sewa']);
				$this->excel->getActiveSheet()->getStyle('S'.$x)->getNumberFormat()->setFormatCode('Rp #,##0');
				$this->excel->getActiveSheet()->setCellValue('T'.$x, $rows2['keterangan']);
				$this->excel->getActiveSheet()->getStyle('T'.$x)->getAlignment()->setWrapText(true);

				$this->excel->getActiveSheet()->setCellValue('B4', strtoupper("Data Tenant"));
				$this->excel->getActiveSheet()->setCellValue('B5', $date);	

			}
		}

		$styleArray = array(
			'borders' => array(
			    'allborders' => array(
			    'style' => PHPExcel_Style_Border::BORDER_THIN
			    )
			),
			'font'  => array(
			    'size'  => 9,
			    'name'  => 'verdana'
			)
		);

		$this->excel->getActiveSheet()->getStyle('B8:T'.$x)->applyFromArray($styleArray);
		unset($styleArray);

		$styleArray1 = array(
		    'font'  => array(
		    'bold'  => true,
		    'uppercase' => true,
		    'size'  => 11,
		    'name'  => 'Calibri'
		    )
		);

		$this->excel->getActiveSheet()->getColumnDimension('B')->setWidth(11);	
		$this->excel->getActiveSheet()->getColumnDimension('C')->setWidth(46);
		$this->excel->getActiveSheet()->getColumnDimension('D')->setWidth(26);
		$this->excel->getActiveSheet()->getColumnDimension('E')->setWidth(26);
		$this->excel->getActiveSheet()->getColumnDimension('F')->setWidth(36);
		$this->excel->getActiveSheet()->getColumnDimension('G')->setWidth(41);
		$this->excel->getActiveSheet()->getColumnDimension('H')->setWidth(63);
		$this->excel->getActiveSheet()->getColumnDimension('I')->setWidth(22);
		$this->excel->getActiveSheet()->getColumnDimension('J')->setWidth(22);
		$this->excel->getActiveSheet()->getColumnDimension('K')->setWidth(22);
		$this->excel->getActiveSheet()->getColumnDimension('L')->setWidth(22);
		$this->excel->getActiveSheet()->getColumnDimension('M')->setWidth(43);
		$this->excel->getActiveSheet()->getColumnDimension('N')->setWidth(22);
		$this->excel->getActiveSheet()->getColumnDimension('O')->setWidth(36);
		$this->excel->getActiveSheet()->getColumnDimension('P')->setWidth(22);
		$this->excel->getActiveSheet()->getColumnDimension('Q')->setWidth(22);
		$this->excel->getActiveSheet()->getColumnDimension('R')->setWidth(22);
		$this->excel->getActiveSheet()->getColumnDimension('S')->setWidth(35);
		$this->excel->getActiveSheet()->getColumnDimension('T')->setWidth(40);

	/*	$this->excel->getActiveSheet()->getStyle('D1:E'.$this->excel->getActiveSheet()->getHighestRow())->getNumberFormat()->setFormatCode('#,##0.00'); 

		$this->excel->getActiveSheet()->getStyle('C1:C'.$this->excel->getActiveSheet()->getHighestRow())
    	->getAlignment()->setWrapText(true);
    	$this->excel->getActiveSheet()->getStyle('E1:E'.$this->excel->getActiveSheet()->getHighestRow())
    	->getAlignment()->setWrapText(true);*/

		//set aligment to center for that merged cell (A1 to D1)
		// $this->excel->getActiveSheet()->getStyle('B1:B2')->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
		$this->excel->getActiveSheet()->getStyle('B4:B5')->getFont()->setBold(true);

		$filename= 'Data Tenant_'.$date.'.xls'; //save our workbook as this file name
		header('Content-Type: application/vnd.ms-excel'); //mime type
		header('Content-Disposition: attachment;filename="'.$filename.'"'); //tell browser what's the file name
		header('Cache-Control: max-age=0'); //no cache
		header('Content-Type: text/html; charset=utf-8');
			             
		//save it to Excel5 format (excel 2003 .XLS file), change this to 'Excel2007' (and adjust the filename extension, also the header mime type)
		//if you want to save it as .XLSX Excel 2007 format
		$objWriter = PHPExcel_IOFactory::createWriter($this->excel, 'Excel5');  
		//force user to download the Excel file without writing it to server's HD
		$objWriter->save('php://output');
	}

	function surat_penyelenggara_satuan()
	{
		$no_surat=get('no_surat');
		$x=0;

		$ls_sql	= " SELECT	*
					FROM	pro_surat_penyelenggara 
					WHERE	UPPER(no_surat)= '$no_surat' AND
							(UPPER(no_surat) LIKE '%".strtoupper(post('keyword'))."%'
							OR UPPER(nama_penyelenggara) LIKE '%".strtoupper(post('keyword'))."%')
					ORDER BY ".(post('sort')=='' ? 'no_surat' : post('sort'))." ".(post('order')=='' ? 'asc' : post('order'));	
	
		$ls_sql2	= "	SELECT 	COUNT(1)
						FROM	pro_surat_penyelenggara 
						WHERE	(UPPER(no_surat) LIKE '%".strtoupper(post('keyword'))."%'
								OR UPPER(nama_penyelenggara) LIKE '%".strtoupper(post('keyword'))."%')
						ORDER BY ".(post('sort')=='' ? 'no_surat' : post('sort'))." ".(post('order')=='' ? 'asc' : post('order'));	
		
		$total = $this->get_data($ls_sql2);

		$result = $this->db->query($ls_sql);

		$data_p = array(	'rows'=> $result->result_array(), 
								'total' => $total);

		$date = date('d M Y');

		//load our new PHPExcel library
		$this->load->library('excel');
		//activate worksheet number 1
		$this->excel->setActiveSheetIndex(0);
		//name the worksheet
		$this->excel->getActiveSheet()->setTitle("Data Penyelenggara");

		$no = 1;

		if ($data_p) {

			$styleArrayBorder = array(
				'borders' => array(
					'allborders' => array(
					'style' => PHPExcel_Style_Border::BORDER_THIN
					)
				)
			);

			$styleArrayUnderline = array(
			 'font' => array(
			 'underline' => PHPExcel_Style_Font::UNDERLINE_SINGLE,
			 'name' => 'Calibri',
			 'size' => 11,
			 'bold' => true
			 )
			);

			$styleArrayDefault = array(
			 'font' => array(
			 'name' => 'Calibri',
			 'size' => 11,
			 )
			);

			$styleArrayItalic = array(
			 'font' => array(
			 'name' => 'Calibri',
			 'size' => 11,
			 'italic' => true
			 )
			);

			$styleArrayFont = array(
			 'font' => array(
			 'name' => 'Calibri',
			 'size' => 9,
			 'color' => array('rgb' => 'FF4719'),
			 )
			);

			$styleArrayFont1 = array(
			 'font' => array(
			 'name' => 'Calibri',
			 'size' => 9,
			 'color' => array('rgb' => '1919FF'),
			 )
			);

			$rows = $data_p['rows'];
			$rows2 = $rows[0];



			$this->excel->getActiveSheet()->setCellValue('E1', strtoupper('SURAT IZIN PENYELENGGARAN KEGIATAN'));
			$this->excel->getActiveSheet()->getStyle('E1')->getFont()->setBold(true);
			$this->excel->getActiveSheet()->setCellValue('E2', 'PRIMKOKAS - KRAKATAU JUNCTION');
			$this->excel->getActiveSheet()->setCellValue('E3', $rows2['no_surat']);
			$this->excel->getActiveSheet()->getStyle('E2')->applyFromArray($styleArrayUnderline);
			$this->excel->getActiveSheet()->getStyle('E1:E3')->getAlignment()->setVertical(PHPExcel_Style_Alignment::VERTICAL_CENTER);	
			$this->excel->getActiveSheet()->getStyle('E1:E3')->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_CENTER);

			$this->excel->getActiveSheet()->setCellValue('A5', 'Puji syukur kehadirat Allah SWT, teriring doa semoga Bapak/Ibu dalam keaadan');
			$this->excel->getActiveSheet()->setCellValue('A6', 'sehat wal afiat dan senantiasa mendapat lindungan-nya di dalam menjalankan tugas');
			$this->excel->getActiveSheet()->setCellValue('A7', 'sehari-hari. Amin');

			$this->excel->getActiveSheet()->setCellValue('A9', 'Dengan ini Primkokas');
			$this->excel->getActiveSheet()->setCellValue('C9','Memberikan Izin');
			$this->excel->getActiveSheet()->setCellValue('E9', 'Kepada :');
			$this->excel->getActiveSheet()->getStyle('C9')->getFont()->setBold(true);
			$this->excel->getActiveSheet()->setCellValue('A10', 'Nama Penyelenggara ');
			$this->excel->getActiveSheet()->setCellValue('C10', ':');
			$this->excel->getActiveSheet()->setCellValue('D10', $rows2['nama_penyelenggara']);
			$this->excel->getActiveSheet()->setCellValue('A11', 'Alamat ');
			$this->excel->getActiveSheet()->setCellValue('C11', ':');
			$this->excel->getActiveSheet()->setCellValue('D11', $rows2['alamat']);
			$this->excel->getActiveSheet()->setCellValue('A12', 'Diwakili Oleh');
			$this->excel->getActiveSheet()->setCellValue('C12', ':');
			$this->excel->getActiveSheet()->setCellValue('D12', $rows2['diwakili_oleh']);

			$this->excel->getActiveSheet()->setCellValue('A14',  'Adapun keterangan kegiatan adalah sebagai berikut :');
			
			$this->excel->getActiveSheet()->setCellValue('A16', 'Nama Kegiatan');
			$this->excel->getActiveSheet()->setCellValue('C16', ':');
			$this->excel->getActiveSheet()->setCellValue('D16', $rows2['nama_kegiatan']);
			$this->excel->getActiveSheet()->setCellValue('A17', 'Keterangan Kegiatan');
			$this->excel->getActiveSheet()->setCellValue('C17', ':');
			$this->excel->getActiveSheet()->setCellValue('D17', $rows2['catatan_kegiatan']);
			$this->excel->getActiveSheet()->getStyle('A17:D17')->getAlignment()->setVertical(PHPExcel_Style_Alignment::VERTICAL_TOP);	
			$this->excel->getActiveSheet()->getStyle('A17:D17')->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_LEFT);
			$this->excel->getActiveSheet()->mergeCells('D17:F17');
			$this->excel->getActiveSheet()->getStyle('D17:F17')->getAlignment()->setWrapText(true);

			$this->excel->getActiveSheet()->setCellValue('A18', 'Hari/Tanggal Kegiatan');
			$this->excel->getActiveSheet()->setCellValue('C18', ':');
			$this->excel->getActiveSheet()->setCellValue('D18', $rows2['tanggal_mulai_kegiatan'].' S/D '.$rows2['tanggal_selesai_kegiatan']);
			$this->excel->getActiveSheet()->setCellValue('A19', 'Pukul');
			$this->excel->getActiveSheet()->setCellValue('C19', ':');
			$this->excel->getActiveSheet()->setCellValue('D19', $rows2['pukul']);
			$this->excel->getActiveSheet()->getStyle('D19')->getNumberFormat()->setFormatCode(PHPExcel_Style_NumberFormat::FORMAT_TEXT);
			$this->excel->getActiveSheet()->setCellValue('A20', 'Tempat Kegiatan');
			$this->excel->getActiveSheet()->setCellValue('C20', ':');
			$this->excel->getActiveSheet()->setCellValue('D20', $rows2['tempat_kegiatan']);

			$this->excel->getActiveSheet()->setCellValue('A22', 'Dengan Catatan Sebagai Berikut :');
			$this->excel->getActiveSheet()->setCellValue('A23', '1. Menjaga norma-norma kesopanan.');
			$this->excel->getActiveSheet()->setCellValue('A24', '2. Tidak mengganggu kenyamanan Krakatau Junction.');
			$this->excel->getActiveSheet()->setCellValue('A25', '3. Menjaga keamanan, ketertiban dan kebersihan selama kegiatan berlangsung.');
			$this->excel->getActiveSheet()->setCellValue('A26', '4. Tidak diperkenankan membawa senjata tajam, minuman beralkohol dan benda');
			$this->excel->getActiveSheet()->setCellValue('A27', '     lainnya yang melanggar hukum di area Krakatau Junction');
			$this->excel->getActiveSheet()->setCellValue('A28', '5. Apabila terjadi pelanggaran, maka pihak keamanan Krakatau Junction berhak untuk');
			$this->excel->getActiveSheet()->setCellValue('A29', '     meberhentikan kegiatan tersebut.');

			$this->excel->getActiveSheet()->setCellValue('A31', 'Demikian surat keterangan ini kami buat untuk dapat di pergunakan sebagaimana');
			$this->excel->getActiveSheet()->setCellValue('A32', 'mestinya.');

			$this->excel->getActiveSheet()->setCellValue('G34', 'Cilegon, '.$date);
			$this->excel->getActiveSheet()->setCellValue('G35', 'PRIMER KOPRASI KARYAWAN');
			$this->excel->getActiveSheet()->setCellValue('G36', 'KRAKATAU STEEL');
			$this->excel->getActiveSheet()->getStyle('G34:G36')->getFont()->setBold(true);


			$this->excel->getActiveSheet()->setCellValue('G41', 'Ngajito');
			$this->excel->getActiveSheet()->setCellValue('G42', 'Property');
			$this->excel->getActiveSheet()->getStyle('G34:G42')->getAlignment()->setVertical(PHPExcel_Style_Alignment::VERTICAL_CENTER);	
			$this->excel->getActiveSheet()->getStyle('G34:G42')->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
			$this->excel->getActiveSheet()->getStyle('G41')->applyFromArray($styleArrayUnderline);

			$this->excel->getActiveSheet()->setCellValue('B42', 'Cc. Arsip');
			
			// $this->excel->getActiveSheet()->getStyle('E45:I45')->applyFromArray($styleArrayUnderline);
			// $this->excel->getActiveSheet()->getStyle('E39:I46')->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_CENTER);

		}

		$this->excel->getActiveSheet()->getColumnDimension('A')->setWidth(8.8);
		$this->excel->getActiveSheet()->getColumnDimension('B')->setWidth(10.67);
		$this->excel->getActiveSheet()->getColumnDimension('C')->setWidth(0.83);
		$this->excel->getActiveSheet()->getColumnDimension('D')->setWidth(15.41);
		$this->excel->getActiveSheet()->getRowDimension('17')->setRowHeight(80);
		$this->excel->getActiveSheet()->getColumnDimension('E')->setWidth(8.43);
		$this->excel->getActiveSheet()->getColumnDimension('F')->setWidth(8.43);
		$this->excel->getActiveSheet()->getColumnDimension('G')->setWidth(10.86);

/*
		$this->excel->getActiveSheet()->getStyle('D1:C'.$this->excel->getActiveSheet()->getHighestRow())->getNumberFormat()->setFormatCode('#,##0.00'); 

		$this->excel->getActiveSheet()->getStyle('C1:C'.$this->excel->getActiveSheet()->getHighestRow())
    	->getAlignment()->setWrapText(true);
    	$this->excel->getActiveSheet()->getStyle('G1:G'.$this->excel->getActiveSheet()->getHighestRow())
    	->getAlignment()->setWrapText(true);*/

		//set aligment to center for that merged cell (A1 to D1)
		// $this->excel->getActiveSheet()->getStyle('B1:B2')->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
		//$this->excel->getActiveSheet()->getStyle('B4:B5')->getFont()->setBold(true);

		$filename= 'Data Penyelenggara_'.$rows2['no_surat'].'.xls'; //save our workbook as this file name
		header('Content-Type: application/vnd.ms-excel'); //mime type
		header('Content-Disposition: attachment;filename="'.$filename.'"'); //tell browser what's the file name
		header('Cache-Control: max-age=0'); //no cache
			             
		//save it to Excel5 format (excel 2003 .XLS file), change this to 'Excel2007' (and adjust the filename extension, also the header mime type)
		//if you want to save it as .XLSX Excel 2007 format
		$objWriter = PHPExcel_IOFactory::createWriter($this->excel, 'Excel5');  
		//force user to download the Excel file without writing it to server's HD
		$objWriter->save('php://output');
	}

	function calon_penyewa_all()
	{

		$status_tenant='Tenant';
		$tanggal=get('tanggal');
		$x=0;

		$ls_sql	= " SELECT	*
					FROM	pro_tenant
					WHERE	UPPER(status_tenant) = 'CALON TENANT' AND
							(UPPER(no_tenant) LIKE '%".strtoupper(post('keyword'))."%'
							OR UPPER(nama_tenant) LIKE '%".strtoupper(post('keyword'))."%'
							OR UPPER(no_toko) LIKE '%".strtoupper(post('keyword'))."%'
							OR UPPER(luas_tempat) LIKE '%".strtoupper(post('keyword'))."%'
							OR UPPER(lokasi_tempat) LIKE '%".strtoupper(post('keyword'))."%'
							OR UPPER(jenis_usaha) LIKE '%".strtoupper(post('keyword'))."%'
							OR UPPER(alamat_lengkap) LIKE '%".strtoupper(post('keyword'))."%'
							OR UPPER(status_anggota) LIKE '%".strtoupper(post('keyword'))."%'
							OR UPPER(no_anggota) LIKE '%".strtoupper(post('keyword'))."%'
							OR UPPER(no_id_card) LIKE '%".strtoupper(post('keyword'))."%'
							OR UPPER(no_telephone) LIKE '%".strtoupper(post('keyword'))."%'
							OR UPPER(no_handphone) LIKE '%".strtoupper(post('keyword'))."%'
							OR UPPER(status_tenant) LIKE '%".strtoupper(post('keyword'))."%'
							OR UPPER(no_kontrak) LIKE '%".strtoupper(post('keyword'))."%'
							OR UPPER(periode_awal_sewa) LIKE '%".strtoupper(post('keyword'))."%'
							OR UPPER(periode_akhir_sewa) LIKE '%".strtoupper(post('keyword'))."%'
							OR UPPER(jangka_waktu) LIKE '%".strtoupper(post('keyword'))."%'
							OR UPPER(harga_sewa) LIKE '%".strtoupper(post('keyword'))."%'
							OR UPPER(keterangan) LIKE '%".strtoupper(post('keyword'))."%')
					ORDER BY ".(post('sort')=='' ? 'id_lokasi' : post('sort'))." ".(post('order')=='' ? 'asc' : post('order')).",REGEXP_REPLACE(no_toko, '[0-9]', ''), TO_NUMBER(REGEXP_SUBSTR(no_toko, '[0-9]+'))";	
		
		$ls_sql2	= "	SELECT COUNT(1)
						FROM	pro_tenant
					    WHERE	UPPER(status_tenant) = 'CALON TENANT' AND
							(UPPER(no_tenant) LIKE '%".strtoupper(post('keyword'))."%'
							OR UPPER(nama_tenant) LIKE '%".strtoupper(post('keyword'))."%'
							OR UPPER(no_toko) LIKE '%".strtoupper(post('keyword'))."%'
							OR UPPER(luas_tempat) LIKE '%".strtoupper(post('keyword'))."%'
							OR UPPER(lokasi_tempat) LIKE '%".strtoupper(post('keyword'))."%'
							OR UPPER(jenis_usaha) LIKE '%".strtoupper(post('keyword'))."%'
							OR UPPER(alamat_lengkap) LIKE '%".strtoupper(post('keyword'))."%'
							OR UPPER(status_anggota) LIKE '%".strtoupper(post('keyword'))."%'
							OR UPPER(no_anggota) LIKE '%".strtoupper(post('keyword'))."%'
							OR UPPER(no_id_card) LIKE '%".strtoupper(post('keyword'))."%'
							OR UPPER(no_telephone) LIKE '%".strtoupper(post('keyword'))."%'
							OR UPPER(no_handphone) LIKE '%".strtoupper(post('keyword'))."%'
							OR UPPER(status_tenant) LIKE '%".strtoupper(post('keyword'))."%'
							OR UPPER(no_kontrak) LIKE '%".strtoupper(post('keyword'))."%'
							OR UPPER(periode_awal_sewa) LIKE '%".strtoupper(post('keyword'))."%'
							OR UPPER(periode_akhir_sewa) LIKE '%".strtoupper(post('keyword'))."%'
							OR UPPER(jangka_waktu) LIKE '%".strtoupper(post('keyword'))."%'
							OR UPPER(harga_sewa) LIKE '%".strtoupper(post('keyword'))."%'
							OR UPPER(keterangan) LIKE '%".strtoupper(post('keyword'))."%')
							ORDER BY ".(post('sort')=='' ? 'no_tenant' : post('sort'))." ".(post('order')=='' ? 'asc' : post('order'));
		
		$total = $this->get_data($ls_sql2);

		$result = $this->db->query($ls_sql);

		$data_p = array(	'rows'=> $result->result_array(), 
								'total' => $total);

		$date = date('Y-m-d');

		//load our new PHPExcel library
		$this->load->library('excel');
		//activate worksheet number 1
		$this->excel->setActiveSheetIndex(0);
		//name the worksheet
		$this->excel->getActiveSheet()->setTitle("Data Calon Penyewa_".$date);

		

			
		if ($data_p) {

			$styleArrayBorder = array(
				'borders' => array(
					'allborders' => array(
					'style' => PHPExcel_Style_Border::BORDER_THIN
					)
				)
			);

			$this->excel->getActiveSheet()->setCellValue('B8', 'No Tenant');
			$this->excel->getActiveSheet()->setCellValue('C8', 'Nama Tenant');
			$this->excel->getActiveSheet()->setCellValue('D8', 'No Toko');
			$this->excel->getActiveSheet()->setCellValue('E8', 'Luas Tempat');
			$this->excel->getActiveSheet()->setCellValue('F8', 'Lokasi Tempat');
			$this->excel->getActiveSheet()->setCellValue('G8', 'Jenis Usaha');
			$this->excel->getActiveSheet()->setCellValue('H8', 'Alamat Lengkap');
			$this->excel->getActiveSheet()->setCellValue('I8', 'Staus Anggota');
			$this->excel->getActiveSheet()->setCellValue('J8', 'No Telephone');
			$this->excel->getActiveSheet()->setCellValue('K8', 'No Handphone');
			$this->excel->getActiveSheet()->setCellValue('L8', 'Status Tenant');
			
			$this->excel->getActiveSheet()->getStyle('B8:L8')->getFont()->setBold(true);
			$this->excel->getActiveSheet()->getStyle('B8:L8')->getFill()->applyFromArray(array('type' => PHPExcel_Style_Fill::FILL_SOLID,'startcolor' => array('rgb' => 'B2B2B2')));
			$this->excel->getActiveSheet()->getStyle('B8:L8')->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_CENTER);

			$x = 8;

			for($i=0;$i<=$data_p['total']-1;$i++){
				$x++;

				$rows = $data_p['rows'];
				$rows2 = $rows[$i];

				$this->excel->getActiveSheet()->setCellValue('B'.$x, $rows2['no_tenant']);
				$this->excel->getActiveSheet()->setCellValue('C'.$x, $rows2['nama_tenant']);
				$this->excel->getActiveSheet()->setCellValue('D'.$x, $rows2['no_toko']);
				$this->excel->getActiveSheet()->setCellValue('E'.$x, $rows2['luas_tempat']);
				$this->excel->getActiveSheet()->setCellValue('F'.$x, $rows2['lokasi_tempat']);
				$this->excel->getActiveSheet()->setCellValue('G'.$x, $rows2['jenis_usaha']);
				$this->excel->getActiveSheet()->setCellValue('H'.$x, $rows2['alamat_lengkap']);
				$this->excel->getActiveSheet()->setCellValue('I'.$x, $rows2['status_anggota']);
				$this->excel->getActiveSheet()->setCellValue('J'.$x, $rows2['no_telephone']);
				$this->excel->getActiveSheet()->setCellValue('K'.$x, $rows2['no_handphone']);
				$this->excel->getActiveSheet()->setCellValue('L'.$x, $rows2['status_tenant']);

				$this->excel->getActiveSheet()->setCellValue('B4', strtoupper("Data Calon Penyewa "));
				$this->excel->getActiveSheet()->setCellValue('B5', $date);	

			}
		}

		$styleArray = array(
			'borders' => array(
			    'allborders' => array(
			    'style' => PHPExcel_Style_Border::BORDER_THIN
			    )
			),
			'font'  => array(
			    'size'  => 9,
			    'name'  => 'verdana'
			)
		);

		$this->excel->getActiveSheet()->getStyle('B8:L'.$x)->applyFromArray($styleArray);
		unset($styleArray);

		$styleArray1 = array(
		    'font'  => array(
		    'bold'  => true,
		    'uppercase' => true,
		    'size'  => 11,
		    'name'  => 'Calibri'
		    )
		);

		$this->excel->getActiveSheet()->getColumnDimension('B')->setWidth(22);	
		$this->excel->getActiveSheet()->getColumnDimension('C')->setWidth(22);
		$this->excel->getActiveSheet()->getColumnDimension('D')->setWidth(22);
		$this->excel->getActiveSheet()->getColumnDimension('E')->setWidth(30);
		$this->excel->getActiveSheet()->getColumnDimension('F')->setWidth(22);
		$this->excel->getActiveSheet()->getColumnDimension('G')->setWidth(22);
		$this->excel->getActiveSheet()->getColumnDimension('H')->setWidth(30);
		$this->excel->getActiveSheet()->getColumnDimension('I')->setWidth(22);
		$this->excel->getActiveSheet()->getColumnDimension('J')->setWidth(22);
		$this->excel->getActiveSheet()->getColumnDimension('K')->setWidth(22);
		$this->excel->getActiveSheet()->getColumnDimension('L')->setWidth(22);

	/*	$this->excel->getActiveSheet()->getStyle('D1:E'.$this->excel->getActiveSheet()->getHighestRow())->getNumberFormat()->setFormatCode('#,##0.00'); 

		$this->excel->getActiveSheet()->getStyle('C1:C'.$this->excel->getActiveSheet()->getHighestRow())
    	->getAlignment()->setWrapText(true);
    	$this->excel->getActiveSheet()->getStyle('E1:E'.$this->excel->getActiveSheet()->getHighestRow())
    	->getAlignment()->setWrapText(true);*/

		//set aligment to center for that merged cell (A1 to D1)
		// $this->excel->getActiveSheet()->getStyle('B1:B2')->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
		$this->excel->getActiveSheet()->getStyle('B4:B5')->getFont()->setBold(true);

		$filename= 'Data Calon Penyewa_'.$date.'.xls'; //save our workbook as this file name
		header('Content-Type: application/vnd.ms-excel'); //mime type
		header('Content-Disposition: attachment;filename="'.$filename.'"'); //tell browser what's the file name
		header('Cache-Control: max-age=0'); //no cache
			             
		//save it to Excel5 format (excel 2003 .XLS file), change this to 'Excel2007' (and adjust the filename extension, also the header mime type)
		//if you want to save it as .XLSX Excel 2007 format
		$objWriter = PHPExcel_IOFactory::createWriter($this->excel, 'Excel5');  
		//force user to download the Excel file without writing it to server's HD
		$objWriter->save('php://output');
	}


	function tagihan_listrik_all()
	{
		$status_tenant='Tenant';
		$status_bayar=get('status_bayar');
		$x=0;

		$ls_sql	= "	SELECT		a.no_tagihan_listrik,a.nama_tenant,a.no_toko,
								a.jenis_usaha,a.tanggal,a.kwh_awal_meter,
								a.kwh_akhir_meter,a.kwh_terpakai,a.tarif_per_kwh,
								a.jumlah_pemakaian,a.mcb,a.biaya_beban,a.jumlah_biaya_beban,
								a.total_tagihan,a.lokasi_tempat,a.no_bukti_pembayaran,
								TO_CHAR(a.tgl_bayar,'DD/MM/YYYY') tgl_bayar,
								a.status_bayar, b.nama_bulan, b.id_bulan,
								SUBSTR(a.tanggal, 4, INSTR(a.tanggal, '-')+2) AS tahun,
								SUBSTR(a.tanggal, 0, INSTR(a.tanggal, '-')-1) AS bulan,
								concat(b.nama_bulan,REPLACE(SUBSTR(a.tanggal, 4, INSTR(a.tanggal, '-')+2), '-',b.nama_bulan)) as periode_pembayaran
						FROM	pro_tagihan_listrik a
						LEFT JOIN pro_nama_bulan b ON a.id_bulan = b.id_bulan
						--LEFT JOIN pro_sewa_gedung c ON a.no_toko = c.no_toko--
						WHERE	a.status_bayar = '$status_bayar'  AND
								(UPPER(a.no_tagihan_listrik) LIKE '%".strtoupper(post('keyword'))."%'
								OR UPPER(a.nama_tenant) LIKE '%".strtoupper(post('keyword'))."%'
								OR UPPER(a.no_toko) LIKE '%".strtoupper(post('keyword'))."%'
								OR UPPER(a.jenis_usaha) LIKE '%".strtoupper(post('keyword'))."%'
								OR UPPER(a.lokasi_tempat) LIKE '%".strtoupper(post('keyword'))."%'
								OR UPPER(a.tanggal) LIKE '%".strtoupper(post('keyword'))."%'
								OR UPPER(a.kwh_awal_meter) LIKE '%".strtoupper(post('keyword'))."%'
								OR UPPER(a.kwh_akhir_meter) LIKE '%".strtoupper(post('keyword'))."%'
								OR UPPER(a.kwh_terpakai) LIKE '%".strtoupper(post('keyword'))."%'
								OR UPPER(a.tarif_per_kwh) LIKE '%".strtoupper(post('keyword'))."%'
								OR UPPER(a.jumlah_pemakaian) LIKE '%".strtoupper(post('keyword'))."%'
								OR UPPER(a.mcb) LIKE '%".strtoupper(post('keyword'))."%'
								OR UPPER(a.biaya_beban) LIKE '%".strtoupper(post('keyword'))."%'
								OR UPPER(a.jumlah_biaya_beban) LIKE '%".strtoupper(post('keyword'))."%'
								OR UPPER(a.total_tagihan) LIKE '%".strtoupper(post('keyword'))."%') 
								ORDER BY ".(post('sort')=='' ? 'a.no_tagihan_listrik' : post('sort'))." ".(post('order')=='' ? 'asc' : post('order'));
			
			$ls_sql2= "	SELECT  count(1) 
						from 	PRO_TAGIHAN_LISTRIK 
						WHERE   STATUS_BAYAR = '$status_bayar'  AND
								(UPPER(no_tagihan_listrik) LIKE '%".strtoupper(post('keyword'))."%'
								OR UPPER(nama_tenant) LIKE '%".strtoupper(post('keyword'))."%'
								OR UPPER(no_toko) LIKE '%".strtoupper(post('keyword'))."%'
								OR UPPER(jenis_usaha) LIKE '%".strtoupper(post('keyword'))."%'
								OR UPPER(lokasi_tempat) LIKE '%".strtoupper(post('keyword'))."%'
								OR UPPER(tanggal) LIKE '%".strtoupper(post('keyword'))."%'
								OR UPPER(kwh_awal_meter) LIKE '%".strtoupper(post('keyword'))."%'
								OR UPPER(kwh_akhir_meter) LIKE '%".strtoupper(post('keyword'))."%'
								OR UPPER(kwh_terpakai) LIKE '%".strtoupper(post('keyword'))."%'
								OR UPPER(tarif_per_kwh) LIKE '%".strtoupper(post('keyword'))."%'
								OR UPPER(jumlah_pemakaian) LIKE '%".strtoupper(post('keyword'))."%'
								OR UPPER(mcb) LIKE '%".strtoupper(post('keyword'))."%'
								OR UPPER(biaya_beban) LIKE '%".strtoupper(post('keyword'))."%'
								OR UPPER(jumlah_biaya_beban) LIKE '%".strtoupper(post('keyword'))."%'
								OR UPPER(total_tagihan) LIKE '%".strtoupper(post('keyword'))."%') 
								ORDER BY ".(post('sort')=='' ? 'no_tagihan_listrik' : post('sort'))." ".(post('order')=='' ? 'asc' : post('order'));
		
		$total = $this->get_data($ls_sql2);

		$result = $this->db->query($ls_sql);

		$data_p = array(	'rows'=> $result->result_array(), 
								'total' => $total);

		$date = date('Y-m-d');

		//load our new PHPExcel library
		$this->load->library('excel');
		//activate worksheet number 1
		$this->excel->setActiveSheetIndex(0);
		//name the worksheet
		$this->excel->getActiveSheet()->setTitle("Tagihan Listrik_".$date);

		

			
		if ($data_p) {

			$styleArrayBorder = array(
				'borders' => array(
					'allborders' => array(
					'style' => PHPExcel_Style_Border::BORDER_THIN
					)
				)
			);



			$this->excel->getActiveSheet()->setCellValue('A4', 'No Tagihan Listrik');
			$this->excel->getActiveSheet()->mergeCells('A4:A5');
			$this->excel->getActiveSheet()->setCellValue('B4', 'Tanggal Pembayaran');
			$this->excel->getActiveSheet()->mergeCells('B4:B5');
			$this->excel->getActiveSheet()->setCellValue('C4', 'No Bukti Pembayaran');
			$this->excel->getActiveSheet()->mergeCells('C4:C5');
			$this->excel->getActiveSheet()->setCellValue('D4', 'Nama Tenant');
			$this->excel->getActiveSheet()->mergeCells('D4:D5');
			$this->excel->getActiveSheet()->setCellValue('E4', 'Toko');
			$this->excel->getActiveSheet()->setCellValue('E5', 'No.');
			$this->excel->getActiveSheet()->setCellValue('F4', 'Jenis Usaha');
			$this->excel->getActiveSheet()->mergeCells('F4:F5');
			//$this->excel->getActiveSheet()->setCellValue('G4', 'Jangka Waktu');
			$this->excel->getActiveSheet()->setCellValue('G4', 'Luas');
			$this->excel->getActiveSheet()->setCellValue('G5', ' M2');
			$this->excel->getActiveSheet()->getStyle('A4:J5')->getAlignment()->setVertical(PHPExcel_Style_Alignment::VERTICAL_CENTER);	
			$this->excel->getActiveSheet()->getStyle('A4:J5')->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
			$this->excel->getActiveSheet()->setCellValue('H4', 'Perhitungan Pemakaian');
			$this->excel->getActiveSheet()->mergeCells('H4:I4');
			$this->excel->getActiveSheet()->getStyle('H4:I4')->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
			$this->excel->getActiveSheet()->setCellValue('H5', 'Angka Awal (KWH)');
			$this->excel->getActiveSheet()->setCellValue('I5', 'Angka Akhir (KWH)');
			$this->excel->getActiveSheet()->setCellValue('J4', 'Jumlah Pemakaian (KWH)');
			$this->excel->getActiveSheet()->mergeCells('J4:J5');
			$this->excel->getActiveSheet()->setCellValue('K4', 'Tarif Per KWH');
			$this->excel->getActiveSheet()->setCellValue('K5', 'Per KWH');
			$this->excel->getActiveSheet()->setCellValue('L4', 'Total Pemakaian');
			$this->excel->getActiveSheet()->mergeCells('L4:L5');
			$this->excel->getActiveSheet()->getStyle('J4:O5')->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
			$this->excel->getActiveSheet()->getStyle('J4:O5')->getAlignment()->setVertical(PHPExcel_Style_Alignment::VERTICAL_CENTER);
			$this->excel->getActiveSheet()->setCellValue('M4', 'MCB yang terpakai');
			$this->excel->getActiveSheet()->mergeCells('M4:M5');
			$this->excel->getActiveSheet()->setCellValue('N4', 'Biaya');
			$this->excel->getActiveSheet()->setCellValue('N5', 'Beban');
			$this->excel->getActiveSheet()->setCellValue('O4', 'Total');
			$this->excel->getActiveSheet()->setCellValue('O5', 'Biaya Beban');
			$this->excel->getActiveSheet()->setCellValue('P4', 'Grand Total');
			$this->excel->getActiveSheet()->mergeCells('P4:P5');
			$this->excel->getActiveSheet()->getStyle('M4:P5')->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
			$this->excel->getActiveSheet()->getStyle('M4:P5')->getAlignment()->setVertical(PHPExcel_Style_Alignment::VERTICAL_CENTER);

			
			$this->excel->getActiveSheet()->getStyle('A4:P5')->applyFromArray($styleArrayBorder);
			$this->excel->getActiveSheet()->getStyle('A4:P5')->getFill()->applyFromArray(array('type' => PHPExcel_Style_Fill::FILL_SOLID,'startcolor' => array('rgb' => 'B2B2B2')));
			

			$x = 7;

			for($i=0;$i<=$data_p['total']-1;$i++){
				$x++;

				$rows = $data_p['rows'];
				$rows2 = $rows[$i];

				$this->excel->getActiveSheet()->setCellValue('A'.$x, $rows2['no_tagihan_listrik']);
				$this->excel->getActiveSheet()->setCellValue('B'.$x, $rows2['tgl_bayar']);
				$this->excel->getActiveSheet()->getStyle('A'.$x.':B'.$x)->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
				$this->excel->getActiveSheet()->setCellValue('C'.$x, $rows2['no_bukti_pembayaran']);
				$this->excel->getActiveSheet()->setCellValue('D'.$x, $rows2['nama_tenant']);
				$this->excel->getActiveSheet()->getStyle('C'.$x.':D'.$x)->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_LEFT);
				$this->excel->getActiveSheet()->setCellValue('E'.$x, $rows2['no_toko']);
				$this->excel->getActiveSheet()->setCellValue('F'.$x, $rows2['jenis_usaha']);
				//$this->excel->getActiveSheet()->setCellValue('G'.$x, $rows2['jangka_waktu']);
				$this->excel->getActiveSheet()->setCellValue('G'.$x, 'lll');
				$this->excel->getActiveSheet()->setCellValue('H'.$x, $rows2['kwh_awal_meter']);
				$this->excel->getActiveSheet()->setCellValue('I'.$x, $rows2['kwh_akhir_meter']);
				$this->excel->getActiveSheet()->setCellValue('J'.$x, $rows2['kwh_terpakai']);
				$this->excel->getActiveSheet()->getStyle('E'.$x.':J'.$x)->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
				$this->excel->getActiveSheet()->setCellValue('K'.$x, $rows2['tarif_per_kwh']);
				$this->excel->getActiveSheet()->getStyle('K'.$x)->getNumberFormat()->setFormatCode("Rp #,##0");
				$this->excel->getActiveSheet()->setCellValue('L'.$x, $rows2['jumlah_pemakaian']);
				$this->excel->getActiveSheet()->getStyle('L'.$x)->getNumberFormat()->setFormatCode("Rp #,##0");
				$this->excel->getActiveSheet()->getStyle('K'.$x.':L'.$x)->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_RIGHT);
				$this->excel->getActiveSheet()->setCellValue('M'.$x, $rows2['mcb']);
				$this->excel->getActiveSheet()->getStyle('M'.$x)->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
				$this->excel->getActiveSheet()->setCellValue('N'.$x, $rows2['biaya_beban']);
				$this->excel->getActiveSheet()->getStyle('N'.$x)->getNumberFormat()->setFormatCode("Rp #,##0");
				$this->excel->getActiveSheet()->setCellValue('O'.$x, $rows2['jumlah_biaya_beban']);
				$this->excel->getActiveSheet()->getStyle('O'.$x)->getNumberFormat()->setFormatCode("Rp #,##0");
				$this->excel->getActiveSheet()->setCellValue('P'.$x, $rows2['total_tagihan']);
				$this->excel->getActiveSheet()->getStyle('P'.$x)->getNumberFormat()->setFormatCode("Rp #,##0");
				$this->excel->getActiveSheet()->getStyle('N'.$x.':P'.$x)->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_LEFT);

				$this->excel->getActiveSheet()->setCellValue('A1', strtoupper('Laporan Pemakaian Listrik / KWH Tenant Yang '.$rows2['status_bayar']));
				$this->excel->getActiveSheet()->setCellValue('A2', $date);	
			}
		}

			
			

		$styleArray = array(
			'borders' => array(
			    'allborders' => array(
			    'style' => PHPExcel_Style_Border::BORDER_THIN
			    )
			),
			'font'  => array(
			    'size'  => 9,
			    'name'  => 'verdana'
			)
		);

		$this->excel->getActiveSheet()->getStyle('A8:P'.$x)->applyFromArray($styleArray);
		unset($styleArray);

		$styleArray1 = array(
		    'font'  => array(
		    'bold'  => true,
		    'uppercase' => true,
		    'size'  => 11,
		    'name'  => 'Calibri'
		    )
		);

		$this->excel->getActiveSheet()->getColumnDimension('A')->setWidth(17.3);
		$this->excel->getActiveSheet()->getColumnDimension('B')->setWidth(22);
		$this->excel->getActiveSheet()->getColumnDimension('C')->setWidth(22);
		$this->excel->getActiveSheet()->getColumnDimension('D')->setWidth(40);	
		$this->excel->getActiveSheet()->getColumnDimension('E')->setWidth(9);
		$this->excel->getActiveSheet()->getColumnDimension('F')->setWidth(55);
		$this->excel->getActiveSheet()->getColumnDimension('G')->setWidth(22);
		$this->excel->getActiveSheet()->getColumnDimension('H')->setWidth(22);
		$this->excel->getActiveSheet()->getColumnDimension('I')->setWidth(22);
		$this->excel->getActiveSheet()->getColumnDimension('J')->setWidth(22);
		$this->excel->getActiveSheet()->getColumnDimension('K')->setWidth(25);
		$this->excel->getActiveSheet()->getColumnDimension('L')->setWidth(22);
		$this->excel->getActiveSheet()->getColumnDimension('M')->setWidth(22);
		$this->excel->getActiveSheet()->getColumnDimension('N')->setWidth(22);
		$this->excel->getActiveSheet()->getColumnDimension('O')->setWidth(22);
		$this->excel->getActiveSheet()->getColumnDimension('P')->setWidth(22);
		

	/*	$this->excel->getActiveSheet()->getStyle('D1:E'.$this->excel->getActiveSheet()->getHighestRow())->getNumberFormat()->setFormatCode('#,##0.00'); 

		$this->excel->getActiveSheet()->getStyle('C1:C'.$this->excel->getActiveSheet()->getHighestRow())
    	->getAlignment()->setWrapText(true);
    	$this->excel->getActiveSheet()->getStyle('E1:E'.$this->excel->getActiveSheet()->getHighestRow())
    	->getAlignment()->setWrapText(true);*/

		//set aligment to center for that merged cell (A1 to D1)
		// $this->excel->getActiveSheet()->getStyle('B1:B2')->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
		//$this->excel->getActiveSheet()->getStyle('B4:B5')->getFont()->setBold(true);

		$filename= 'Laporan Tagihan Listrik_'.$date.'.xls'; //save our workbook as this file name
		header('Content-Type: application/vnd.ms-excel'); //mime type
		header('Content-Disposition: attachment;filename="'.$filename.'"'); //tell browser what's the file name
		header('Cache-Control: max-age=0'); //no cache
			             
		//save it to Excel5 format (excel 2003 .XLS file), change this to 'Excel2007' (and adjust the filename extension, also the header mime type)
		//if you want to save it as .XLSX Excel 2007 format
		$objWriter = PHPExcel_IOFactory::createWriter($this->excel, 'Excel5');  
		//force user to download the Excel file without writing it to server's HD
		$objWriter->save('php://output');
	}


	function tagihan_listrik_satuan()
	{
		$id_tagihan=get('no_tagihan_listrik');
		$x=0;

		$ls_sql	= " SELECT		a.no_tagihan_listrik,a.nama_tenant,a.no_toko,
								a.jenis_usaha,a.tanggal,a.kwh_awal_meter,c.luas_tempat,
								a.kwh_akhir_meter,a.kwh_terpakai,a.tarif_per_kwh,
								a.jumlah_pemakaian,a.mcb,a.biaya_beban,a.jumlah_biaya_beban,
								a.total_tagihan,a.lokasi_tempat,a.no_bukti_pembayaran,
								TO_CHAR(a.tgl_bayar,'DD/MM/YYYY') tgl_bayar,
								a.status_bayar, b.nama_bulan, b.id_bulan,
								SUBSTR(a.tanggal, 4, INSTR(a.tanggal, '-')+2) AS tahun,
								SUBSTR(a.tanggal, 0, INSTR(a.tanggal, '-')-1) AS bulan,
								concat(b.nama_bulan,REPLACE(SUBSTR(a.tanggal, 4, INSTR(a.tanggal, '-')+2), '-',b.nama_bulan)) as periode_pembayaran
						FROM	pro_tagihan_listrik a
						LEFT JOIN pro_nama_bulan b ON a.id_bulan = b.id_bulan
						LEFT JOIN pro_sewa_gedung c ON a.no_toko = c.no_toko
						WHERE	UPPER(a.no_tagihan_listrik)='$id_tagihan' AND
								(UPPER(a.no_tagihan_listrik) LIKE '%".strtoupper(post('keyword'))."%'
								OR UPPER(a.nama_tenant) LIKE '%".strtoupper(post('keyword'))."%'
								OR UPPER(a.no_toko) LIKE '%".strtoupper(post('keyword'))."%'
								OR UPPER(a.jenis_usaha) LIKE '%".strtoupper(post('keyword'))."%'
								OR UPPER(a.lokasi_tempat) LIKE '%".strtoupper(post('keyword'))."%'
								OR UPPER(a.tanggal) LIKE '%".strtoupper(post('keyword'))."%'
								OR UPPER(a.kwh_awal_meter) LIKE '%".strtoupper(post('keyword'))."%'
								OR UPPER(a.kwh_akhir_meter) LIKE '%".strtoupper(post('keyword'))."%'
								OR UPPER(a.kwh_terpakai) LIKE '%".strtoupper(post('keyword'))."%'
								OR UPPER(a.tarif_per_kwh) LIKE '%".strtoupper(post('keyword'))."%'
								OR UPPER(a.jumlah_pemakaian) LIKE '%".strtoupper(post('keyword'))."%'
								OR UPPER(a.mcb) LIKE '%".strtoupper(post('keyword'))."%'
								OR UPPER(a.biaya_beban) LIKE '%".strtoupper(post('keyword'))."%'
								OR UPPER(a.jumlah_biaya_beban) LIKE '%".strtoupper(post('keyword'))."%'
								OR UPPER(a.total_tagihan) LIKE '%".strtoupper(post('keyword'))."%') 
								ORDER BY ".(post('sort')=='' ? 'no_tagihan_listrik' : post('sort'))." ".(post('order')=='' ? 'asc' : post('order'));	
	
		$ls_sql2	= "	SELECT COUNT(1)
					    FROM pro_tagihan_listrik a
						WHERE	UPPER(a.no_tagihan_listrik)='$id_tagihan' AND
								(UPPER(a.no_tagihan_listrik) LIKE '%".strtoupper(post('keyword'))."%'
								OR UPPER(a.nama_tenant) LIKE '%".strtoupper(post('keyword'))."%'
								OR UPPER(a.no_toko) LIKE '%".strtoupper(post('keyword'))."%'
								OR UPPER(a.jenis_usaha) LIKE '%".strtoupper(post('keyword'))."%'
								OR UPPER(a.lokasi_tempat) LIKE '%".strtoupper(post('keyword'))."%'
								OR UPPER(a.tanggal) LIKE '%".strtoupper(post('keyword'))."%'
								OR UPPER(a.kwh_awal_meter) LIKE '%".strtoupper(post('keyword'))."%'
								OR UPPER(a.kwh_akhir_meter) LIKE '%".strtoupper(post('keyword'))."%'
								OR UPPER(a.kwh_terpakai) LIKE '%".strtoupper(post('keyword'))."%'
								OR UPPER(a.tarif_per_kwh) LIKE '%".strtoupper(post('keyword'))."%'
								OR UPPER(a.jumlah_pemakaian) LIKE '%".strtoupper(post('keyword'))."%'
								OR UPPER(a.mcb) LIKE '%".strtoupper(post('keyword'))."%'
								OR UPPER(a.biaya_beban) LIKE '%".strtoupper(post('keyword'))."%'
								OR UPPER(a.jumlah_biaya_beban) LIKE '%".strtoupper(post('keyword'))."%'
								OR UPPER(a.total_tagihan) LIKE '%".strtoupper(post('keyword'))."%') 
							ORDER BY ".(post('sort')=='' ? 'no_tagihan_listrik' : post('sort'))." ".(post('order')=='' ? 'asc' : post('order'));	
	
		$total = $this->get_data($ls_sql2);

		$result = $this->db->query($ls_sql);

		$data_p = array(	'rows'=> $result->result_array(), 
								'total' => $total);

		$date = date('d-M-y');

		//load our new PHPExcel library
		$this->load->library('excel');
		//activate worksheet number 1
		$this->excel->setActiveSheetIndex(0);
		//name the worksheet
		$this->excel->getActiveSheet()->setTitle("Tagihan Listrik");

		$no = 1;

		/*$objDrawing = new PHPExcel_Worksheet_Drawing();
			$objDrawing->setName('Logo');
			$objDrawing->setDescription('Logo');
			$objDrawing->setPath('http://localhost/primkokas-new/files/logo_report.png');
			$objDrawing->setCoordinates('B1');
			$objDrawing->setHeight(36);*/
			
			/*$objPHPExcel = new PHPExcel();
			$sheet = $objPHPExcel->setSheetIndexAndTitle(1, "YOUR_SHEET_TITLE"); // first sheet
			$objDrawing = new PHPExcel_Worksheet_Drawing();
			$objDrawing->setName('Logo');
			$objDrawing->setDescription('Logo');
			$logo = base_path() . '/images/logo.png'; // Provide path to your logo file
			$objDrawing->setPath($logo);
			$objDrawing->setOffsetX(8);    // setOffsetX works properly
			$objDrawing->setOffsetY(300);  //setOffsetY has no effect
			$objDrawing->setCoordinates('B1');
			$objDrawing->setHeight(75); // logo height
			$objDrawing->setWorksheet($sheet);*/ 

		if ($data_p) {

			$styleArrayBorder = array(
				'borders' => array(
					'allborders' => array(
					'style' => PHPExcel_Style_Border::BORDER_THIN
					)
				)
			);

			$styleArrayUnderline = array(
			 'font' => array(
			 'underline' => PHPExcel_Style_Font::UNDERLINE_SINGLE,
			 'name' => 'Century Gothic',
			 'size' => 11,
			 'bold' => true
			 )
			);

			$styleArrayDefault = array(
			 'font' => array(
			 'name' => 'Century Gothic',
			 'size' => 11,
			 )
			);

			$styleArrayItalic = array(
			 'font' => array(
			 'name' => 'Century Gothic',
			 'size' => 11,
			 'italic' => true
			 )
			);

			$objDrawing = new PHPExcel_Worksheet_Drawing();
			$objDrawing->setName('Logo');
			$objDrawing->setDescription('Logo');
			$objDrawing->setPath(APPPATH.'file/media/logo_primkokas1.jpg');
			$objDrawing->setCoordinates('E2');
			$objDrawing->setHeight(280);
			$objDrawing->setWidth(270);
			$objDrawing->setWorksheet($this->excel->getActiveSheet());

			$this->excel->getActiveSheet()->setCellValue('B3', 'Tagihan Listrik Bulan');
			$this->excel->getActiveSheet()->setCellValue('B6', 'No Tagihan Listrik');
			$this->excel->getActiveSheet()->setCellValue('B7', 'Tanggal Pembayaran');
			$this->excel->getActiveSheet()->setCellValue('B8', 'No Bukti Pembayaran');
			$this->excel->getActiveSheet()->setCellValue('B9', 'No Toko');
			$this->excel->getActiveSheet()->setCellValue('B10', 'Nama Pelanggan');
			$this->excel->getActiveSheet()->setCellValue('B11', 'Jenis Usaha');
			$this->excel->getActiveSheet()->setCellValue('B13', 'Kwh Awal Meter');
			$this->excel->getActiveSheet()->setCellValue('B14', 'Kwh Akhir Meter');
			$this->excel->getActiveSheet()->setCellValue('B15', 'Kwh Terpakai');
			$this->excel->getActiveSheet()->setCellValue('B16', 'Tarif Per Kwh');
			$this->excel->getActiveSheet()->setCellValue('B17', 'Jumlah Pemakaian');
			$this->excel->getActiveSheet()->setCellValue('B19', 'MCB (A)');
			$this->excel->getActiveSheet()->setCellValue('B20', 'Biaya Beban');
			$this->excel->getActiveSheet()->setCellValue('B21', 'Jumlah Biaya Beban');
			$this->excel->getActiveSheet()->setCellValue('B23', 'Total Tagihan');
			$this->excel->getActiveSheet()->setCellValue('B24', 'Terbilang');
			$this->excel->getActiveSheet()->setCellValue('B29', 'Mengetahui');
			$this->excel->getActiveSheet()->setCellValue('B34', 'Nanang Rosdiana');
			$this->excel->getActiveSheet()->setCellValue('B35', 'Finance Div. Mgr');
			$this->excel->getActiveSheet()->setCellValue('B40', 'Pembayaran dapat dilakukan malalui transfer via rekening No. 155-00-0259247-8');
			$this->excel->getActiveSheet()->setCellValue('B41', 'a/n Property PRIMKOKAS di Bank Mandiri Cab. Cilegon – Anyer atau setor langsung');
			$this->excel->getActiveSheet()->setCellValue('B42', 'ke kasir Primkokas. Pembayaran syah setelah uang dapat dicairkan');
			$this->excel->getActiveSheet()->setCellValue('B42', 'atau disetor dengan bukti  kwitansi.');
			
			$this->excel->getActiveSheet()->getStyle('B29:B35')->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
			//unset($styleArrayUnderline);

			$this->excel->getActiveSheet()->setCellValue('C3', ':');
			$this->excel->getActiveSheet()->setCellValue('C6', ':');
			$this->excel->getActiveSheet()->setCellValue('C7', ':');
			$this->excel->getActiveSheet()->setCellValue('C8', ':');
			$this->excel->getActiveSheet()->setCellValue('C9', ':');
			$this->excel->getActiveSheet()->setCellValue('C10', ':');
			$this->excel->getActiveSheet()->setCellValue('C11', ':');
			$this->excel->getActiveSheet()->setCellValue('C13', ':');
			$this->excel->getActiveSheet()->setCellValue('C14', ':');
			$this->excel->getActiveSheet()->setCellValue('C15', ':');
			$this->excel->getActiveSheet()->setCellValue('C17', ':');
			$this->excel->getActiveSheet()->setCellValue('C19', ':');
			$this->excel->getActiveSheet()->setCellValue('C20', ':');
			$this->excel->getActiveSheet()->setCellValue('C21', ':');
			$this->excel->getActiveSheet()->setCellValue('C22', ':');
			$this->excel->getActiveSheet()->setCellValue('C23', ':');
			$this->excel->getActiveSheet()->setCellValue('C24', ':');

			$this->excel->getActiveSheet()->setCellValue('E23', '(Jml Pemakaian + Jml Biaya Beban)');
			$this->excel->getActiveSheet()->setCellValue('F27', 'Cilegon'."".','.$date.'');
			$this->excel->getActiveSheet()->setCellValue('F28', 'PRIMER KOPERASI KARYAWAN');
			$this->excel->getActiveSheet()->setCellValue('F29', 'KRAKATAU STEEL');
			$this->excel->getActiveSheet()->setCellValue('F34', 'Ngatijo');
			$this->excel->getActiveSheet()->setCellValue('F35', 'Property Div.');
			
			


			
			$this->excel->getActiveSheet()->getStyle('F27:F35')->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
			$this->excel->getActiveSheet()->getStyle('B40:F42')->applyFromArray($styleArrayItalic);
			$this->excel->getActiveSheet()->getStyle('B35:F35')->getFont()->setBold(true);
			//$this->excel->getActiveSheet()->getStyle('B8:B17')->getFill()->applyFromArray(array('type' => PHPExcel_Style_Fill::FILL_SOLID,'startcolor' => array('rgb' => 'EEEE11')));
			//$this->excel->getActiveSheet()->getStyle('B8:B17')->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_CENTER);

				$rows = $data_p['rows'];
				$rows2 = $rows[0];

				$this->excel->getActiveSheet()->setCellValue('B5', $rows2['lokasi_tempat']." ".'Krakatau Juction');
				$this->excel->getActiveSheet()->setCellValue('D3', $rows2['periode_pembayaran']);
				$this->excel->getActiveSheet()->setCellValue('D6', $rows2['no_tagihan_listrik']);
				$this->excel->getActiveSheet()->setCellValue('D7', $rows2['tgl_bayar']);
				$this->excel->getActiveSheet()->setCellValue('D8', $rows2['no_bukti_pembayaran']);
				$this->excel->getActiveSheet()->setCellValue('D9', $rows2['no_toko']);
				$this->excel->getActiveSheet()->setCellValue('D10', $rows2['nama_tenant']);
				$this->excel->getActiveSheet()->setCellValue('D11', $rows2['jenis_usaha']);
				$this->excel->getActiveSheet()->setCellValue('D13', $rows2['kwh_awal_meter']);
				$this->excel->getActiveSheet()->setCellValue('D14', $rows2['kwh_akhir_meter']);
				$this->excel->getActiveSheet()->setCellValue('D15', $rows2['kwh_terpakai']);
				$this->excel->getActiveSheet()->getStyle('D13:D15')->getNumberFormat()->setFormatCode("#,##0");
				$this->excel->getActiveSheet()->setCellValue('D16', $rows2['tarif_per_kwh']);
				$this->excel->getActiveSheet()->getStyle('D16')->getNumberFormat()->setFormatCode("Rp #,##0");
				$this->excel->getActiveSheet()->setCellValue('D17', $rows2['jumlah_pemakaian']);
				$this->excel->getActiveSheet()->getStyle('D17')->getNumberFormat()->setFormatCode("Rp #,##0");
				$this->excel->getActiveSheet()->setCellValue('D19', $rows2['mcb']);
				$this->excel->getActiveSheet()->setCellValue('D21', $rows2['biaya_beban']);
				$this->excel->getActiveSheet()->getStyle('D21')->getNumberFormat()->setFormatCode("Rp #,##0");
				$this->excel->getActiveSheet()->setCellValue('D22', $rows2['jumlah_biaya_beban']);
				$this->excel->getActiveSheet()->getStyle('D22')->getNumberFormat()->setFormatCode("Rp #,##0");
				$this->excel->getActiveSheet()->setCellValue('D23', $rows2['total_tagihan'] );
				$this->excel->getActiveSheet()->getStyle('D23')->getNumberFormat()->setFormatCode("Rp #,##0");
				$this->excel->getActiveSheet()->setCellValue('D24', "# ".$this->toTerbilang($rows2['total_tagihan'])." Rupiah #");
				$this->excel->getActiveSheet()->getStyle('D24')->applyFromArray($styleArrayItalic);

				$this->excel->getActiveSheet()->getStyle('D23:D24')->getFont()->setBold(true);
				//$this->excel->getActiveSheet()->getStyle('B34:F35')->getFont()->setBold(true);

				$this->excel->getActiveSheet()->getStyle('B3:E34')->applyFromArray($styleArrayDefault);
				//unset($styleArrayDefault);
				$this->excel->getActiveSheet()->getStyle('E23')->applyFromArray($styleArrayItalic);
				$this->excel->getActiveSheet()->getStyle('B34:F34')->applyFromArray($styleArrayUnderline);


		}

		
					

	/*	$styleArray = array(
			'borders' => array(
			    'allborders' => array(
			    'style' => PHPExcel_Style_Border::BORDER_THIN
			    )
			),
			'font'  => array(
			    'size'  => 9,
			    'name'  => 'verdana'
			)
		);

		$this->excel->getActiveSheet()->getStyle('B8:C'.$x)->applyFromArray($styleArray);
		unset($styleArray);*/

		/*$styleArray1 = array(
		    'font'  => array(
		    'bold'  => true,
		    'uppercase' => true,
		    'size'  => 11,
		    'name'  => 'Calibri'
		    )
		);*/
		
		$this->excel->getActiveSheet()->getColumnDimension('A')->setWidth(1.7);
		$this->excel->getActiveSheet()->getColumnDimension('B')->setWidth(25);
		$this->excel->getActiveSheet()->getColumnDimension('C')->setWidth(1.86);
		$this->excel->getActiveSheet()->getColumnDimension('D')->setWidth(19);
		$this->excel->getActiveSheet()->getColumnDimension('E')->setWidth(12.57);
		$this->excel->getActiveSheet()->getColumnDimension('F')->setWidth(9);
		$this->excel->getActiveSheet()->getColumnDimension('G')->setWidth(8.57);


		$this->excel->getActiveSheet()->getStyle('D1:C'.$this->excel->getActiveSheet()->getHighestRow())->getNumberFormat()->setFormatCode('#,##0.00'); 

		$this->excel->getActiveSheet()->getStyle('C1:C'.$this->excel->getActiveSheet()->getHighestRow())
    	->getAlignment()->setWrapText(true);
    	/*$this->excel->getActiveSheet()->getStyle('G1:G'.$this->excel->getActiveSheet()->getHighestRow())
    	->getAlignment()->setWrapText(true);*/

		//set aligment to center for that merged cell (A1 to D1)
		// $this->excel->getActiveSheet()->getStyle('B1:B2')->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
		//$this->excel->getActiveSheet()->getStyle('B4:B5')->getFont()->setBold(true);

		$filename= 'Laporan Tagihan Listrik_'.$rows2['no_tagihan_listrik'].'.xls'; //save our workbook as this file name
		header('Content-Type: application/vnd.ms-excel'); //mime type
		header('Content-Disposition: attachment;filename="'.$filename.'"'); //tell browser what's the file name
		header('Cache-Control: max-age=0'); //no cache
			             
		//save it to Excel5 format (excel 2003 .XLS file), change this to 'Excel2007' (and adjust the filename extension, also the header mime type)
		//if you want to save it as .XLSX Excel 2007 format
		$objWriter = PHPExcel_IOFactory::createWriter($this->excel, 'Excel5');  
		//force user to download the Excel file without writing it to server's HD
		$objWriter->save('php://output');
	}

	function terbilang($x)
	{
	  $abil = array("", "satu", "dua", "tiga", "empat", "lima", "enam", "tujuh", "delapan", "sembilan", "sepuluh", "sebelas");
	  if ($x < 12)
	    return " " . $abil[$x];
	  elseif ($x < 20)
	    return $this->terbilang($x - 10) . " belas";
	  elseif ($x < 100)
	    return $this->terbilang($x / 10) . " puluh" . $this->terbilang($x % 10);
	  elseif ($x < 200)
	    return " seratus" . terbilang($x - 100);
	  elseif ($x < 1000)
	    return $this->terbilang($x / 100) . " ratus" . $this->terbilang($x % 100);
	  elseif ($x < 2000)
	    return " seribu" . terbilang($x - 1000);
	  /*elseif ($x < 100000)
	    return $this->terbilang($x / 10000) . " puluh ribu" . $this->terbilang($x % 1000);*/
	  elseif ($x < 1000000)
	    return $this->terbilang($x / 1000) . " ribu" . $this->terbilang($x % 1000);
	  elseif ($x < 1000000000)
	    return $this->terbilang($x / 1000000) . " juta" . $this->terbilang($x % 1000000);
	}

	function tagihan_sewa_all()
	{

		$status_tenant='Tenant';
		$status_bayar=get('status_bayar');
		$x=0;
		//var_dump($status_bayar);
		$ls_sql	= " SELECT	a.no_tagihan_sewa,a.nama_tenant,a.no_toko,
							a.jenis_usaha,a.lokasi_tempat,a.harga_sewa,
							a.tanggal_pembayaran,a.status_bayar,
							a.keterangan,TO_CHAR(a.tanggal_bayar,'DD/MM/YYYY') tanggal_bayar,
							a.no_bukti_pembayaran, b.nama_bulan, b.id_bulan,
							SUBSTR(a.tanggal_pembayaran, 4, INSTR(a.tanggal_pembayaran, '-')+2) AS tahun,
							SUBSTR(a.tanggal_pembayaran, 0, INSTR(a.tanggal_pembayaran, '-')-1) AS bulan,
							concat(b.nama_bulan,REPLACE(SUBSTR(a.tanggal_pembayaran, 4, INSTR(a.tanggal_pembayaran, '-')+2), '-',b.nama_bulan)) as periode_pembayaran
					FROM	pro_tagihan_sewa a
					LEFT JOIN pro_nama_bulan b ON a.id_bulan = b.id_bulan
					WHERE	a.status_bayar ='$status_bayar' AND 
							(UPPER(a.no_tagihan_sewa) LIKE '%".strtoupper(post('keyword'))."%'
							OR UPPER(a.nama_tenant) LIKE '%".strtoupper(post('keyword'))."%'
							OR UPPER(a.no_toko) LIKE '%".strtoupper(post('keyword'))."%'
							OR UPPER(a.jenis_usaha) LIKE '%".strtoupper(post('keyword'))."%'
							OR UPPER(a.lokasi_tempat) LIKE '%".strtoupper(post('keyword'))."%'
							OR UPPER(a.harga_sewa) LIKE '%".strtoupper(post('keyword'))."%'
							OR UPPER(a.tanggal_pembayaran) LIKE '%".strtoupper(post('keyword'))."%'
							OR UPPER(a.status_bayar) LIKE '%".strtoupper(post('keyword'))."%')
							ORDER BY ".(post('sort')=='' ? 'a.no_tagihan_sewa' : post('sort'))." ".(post('order')=='' ? 'asc' : post('order'));		
	
		$ls_sql2	= "	SELECT 	COUNT(1)
					    FROM 	pro_tagihan_sewa
						WHERE	status_bayar ='$status_bayar' AND (UPPER(no_tagihan_sewa) LIKE '%".strtoupper(post('keyword'))."%'
								OR UPPER(nama_tenant) LIKE '%".strtoupper(post('keyword'))."%'
								OR UPPER(no_toko) LIKE '%".strtoupper(post('keyword'))."%'
								OR UPPER(jenis_usaha) LIKE '%".strtoupper(post('keyword'))."%'
								OR UPPER(lokasi_tempat) LIKE '%".strtoupper(post('keyword'))."%'
								OR UPPER(harga_sewa) LIKE '%".strtoupper(post('keyword'))."%'
								OR UPPER(tanggal_pembayaran) LIKE '%".strtoupper(post('keyword'))."%'
								OR UPPER(status_bayar) LIKE '%".strtoupper(post('keyword'))."%')
								ORDER BY ".(post('sort')=='' ? 'no_tagihan_sewa' : post('sort'))." ".(post('order')=='' ? 'asc' : post('order'));		
		
		$total = $this->get_data($ls_sql2);

		$result = $this->db->query($ls_sql);

		$data_p = array(	'rows'=> $result->result_array(), 
								'total' => $total);

		$date = date('Y-m-d');

		//load our new PHPExcel library
		$this->load->library('excel');
		//activate worksheet number 1
		$this->excel->setActiveSheetIndex(0);
		//name the worksheet
		$this->excel->getActiveSheet()->setTitle("Tagihan Sewa_".$date);

		

			
		if ($data_p) {

			$styleArrayBorder = array(
				'borders' => array(
					'allborders' => array(
					'style' => PHPExcel_Style_Border::BORDER_THIN
					)
				)
			);

			$this->excel->getActiveSheet()->setCellValue('B8', 'No Tagihan Sewa');
			$this->excel->getActiveSheet()->setCellValue('C8', 'Tanggal Pembayaran');
			$this->excel->getActiveSheet()->setCellValue('D8', 'No Bukti Pembayaran');
			$this->excel->getActiveSheet()->setCellValue('E8', 'Nama Tenant');
			$this->excel->getActiveSheet()->setCellValue('F8', 'No Toko');
			$this->excel->getActiveSheet()->setCellValue('G8', 'Jenis Usaha');
			$this->excel->getActiveSheet()->setCellValue('H8', 'Lokasi Tempat');
			$this->excel->getActiveSheet()->setCellValue('I8', 'Periode Pembayaran');
			$this->excel->getActiveSheet()->setCellValue('J8', 'Harga Sewa');
			$this->excel->getActiveSheet()->setCellValue('K8', 'Staus Bayar');
			$this->excel->getActiveSheet()->setCellValue('L8', 'Keterangan');
			
			$this->excel->getActiveSheet()->getStyle('B8:L8')->getFont()->setBold(true);
			$this->excel->getActiveSheet()->getStyle('B8:L8')->getFill()->applyFromArray(array('type' => PHPExcel_Style_Fill::FILL_SOLID,'startcolor' => array('rgb' => 'B2B2B2')));
			$this->excel->getActiveSheet()->getStyle('B8:L8')->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_CENTER);

			$x = 8;

			for($i=0;$i<=$data_p['total']-1;$i++){
				$x++;

				$rows = $data_p['rows'];
				$rows2 = $rows[$i];

				$this->excel->getActiveSheet()->setCellValue('B'.$x, $rows2['no_tagihan_sewa']);
				$this->excel->getActiveSheet()->setCellValue('C'.$x, $rows2['tanggal_bayar']);
				$this->excel->getActiveSheet()->getStyle('B'.$x.':C'.$x)->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
				$this->excel->getActiveSheet()->setCellValue('D'.$x, $rows2['no_bukti_pembayaran']);
				$this->excel->getActiveSheet()->setCellValue('E'.$x, $rows2['nama_tenant']);
				$this->excel->getActiveSheet()->getStyle('D'.$x.':E'.$x)->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_LEFT);
				$this->excel->getActiveSheet()->setCellValue('F'.$x, $rows2['no_toko']);
				$this->excel->getActiveSheet()->getStyle('F'.$x)->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
				$this->excel->getActiveSheet()->setCellValue('G'.$x, $rows2['jenis_usaha']);
				$this->excel->getActiveSheet()->setCellValue('H'.$x, $rows2['lokasi_tempat']);
				$this->excel->getActiveSheet()->setCellValue('J'.$x, $rows2['periode_pembayaran']);
				$this->excel->getActiveSheet()->getStyle('G'.$x.':I'.$x)->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_LEFT);
				$this->excel->getActiveSheet()->setCellValue('J'.$x, $rows2['harga_sewa']);
				$this->excel->getActiveSheet()->getStyle('J'.$x)->getNumberFormat()->setFormatCode("Rp #,##0");
				$this->excel->getActiveSheet()->getStyle('J'.$x)->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_RIGHT);
				$this->excel->getActiveSheet()->setCellValue('K'.$x, $rows2['status_bayar']);
				$this->excel->getActiveSheet()->getStyle('K'.$x)->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
				$this->excel->getActiveSheet()->setCellValue('L'.$x, $rows2['keterangan']);
				$this->excel->getActiveSheet()->getStyle('L'.$x)->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_LEFT);

				$this->excel->getActiveSheet()->setCellValue('B4', strtoupper("Laporan Tagihan Sewa ".$rows2['status_bayar']));
				$this->excel->getActiveSheet()->setCellValue('B5', $date);	

			}
		}

		$styleArray = array(
			'borders' => array(
			    'allborders' => array(
			    'style' => PHPExcel_Style_Border::BORDER_THIN
			    )
			),
			'font'  => array(
			    'size'  => 9,
			    'name'  => 'verdana'
			)
		);

		$this->excel->getActiveSheet()->getStyle('B8:L'.$x)->applyFromArray($styleArray);
		unset($styleArray);

		$styleArray1 = array(
		    'font'  => array(
		    'bold'  => true,
		    'uppercase' => true,
		    'size'  => 11,
		    'name'  => 'Calibri'
		    )
		);

		$this->excel->getActiveSheet()->getColumnDimension('B')->setWidth(22);	
		$this->excel->getActiveSheet()->getColumnDimension('C')->setWidth(22);
		$this->excel->getActiveSheet()->getColumnDimension('D')->setWidth(22);
		$this->excel->getActiveSheet()->getColumnDimension('E')->setWidth(60);
		$this->excel->getActiveSheet()->getColumnDimension('F')->setWidth(22);
		$this->excel->getActiveSheet()->getColumnDimension('G')->setWidth(60);
		$this->excel->getActiveSheet()->getColumnDimension('H')->setWidth(22);
		$this->excel->getActiveSheet()->getColumnDimension('I')->setWidth(22);
		$this->excel->getActiveSheet()->getColumnDimension('J')->setWidth(27);
		$this->excel->getActiveSheet()->getColumnDimension('K')->setWidth(22);
		$this->excel->getActiveSheet()->getColumnDimension('L')->setWidth(22);

	/*	$this->excel->getActiveSheet()->getStyle('D1:E'.$this->excel->getActiveSheet()->getHighestRow())->getNumberFormat()->setFormatCode('#,##0.00'); 

		$this->excel->getActiveSheet()->getStyle('C1:C'.$this->excel->getActiveSheet()->getHighestRow())
    	->getAlignment()->setWrapText(true);
    	$this->excel->getActiveSheet()->getStyle('E1:E'.$this->excel->getActiveSheet()->getHighestRow())
    	->getAlignment()->setWrapText(true);*/

		//set aligment to center for that merged cell (A1 to D1)
		// $this->excel->getActiveSheet()->getStyle('B1:B2')->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
		$this->excel->getActiveSheet()->getStyle('B4:B5')->getFont()->setBold(true);

		//$filename= 'Laporan Tagihan Sewa_'.$rows2['tanggal_pembayaran'] .'.xls'; //save our workbook as this file name
		$filename= 'Laporan Tagihan Sewa_'.$date.'.xls'; //save our workbook as this file name
		
		header('Content-Type: application/vnd.ms-excel'); //mime type
		header('Content-Disposition: attachment;filename="'.$filename.'"'); //tell browser what's the file name
		header('Cache-Control: max-age=0'); //no cache
			             
		//save it to Excel5 format (excel 2003 .XLS file), change this to 'Excel2007' (and adjust the filename extension, also the header mime type)
		//if you want to save it as .XLSX Excel 2007 format
		$objWriter = PHPExcel_IOFactory::createWriter($this->excel, 'Excel5');  
		//force user to download the Excel file without writing it to server's HD
		$objWriter->save('php://output');
	}


	function total_pendapatan_sewa()
	{

		$status_tenant='Tenant';
		$status_bayar=get('status_bayar');
		$bulan_dari=get('bulan_dari');
		$bulan_sampai=get('bulan_sampai');
		$tahun=get('tahun');

		/*if($bulan_dari=='01'){
			$bulan_dari='00';
		} else {
			$bulan_dari=get('bulan_dari');
		}*/

		$dari_nol=substr($bulan_dari, 0,1);
		$dari_bulan=substr($bulan_dari, 1,1);
		$t=intval($dari_bulan) - 1;
		$bulan_dari_new = $dari_nol.$t;


		$x=0;
		//var_dump($bulan_dari_new);
		$ls_sql	= " SELECT	a.no_tagihan_sewa,a.nama_tenant,a.no_toko,
							a.jenis_usaha,a.lokasi_tempat,a.harga_sewa,
							a.tanggal_pembayaran,a.status_bayar,
							a.keterangan,TO_CHAR(a.tanggal_bayar,'DD/MM/YYYY') tanggal_bayar,
							a.no_bukti_pembayaran, b.nama_bulan, b.id_bulan,
							SUBSTR(a.tanggal_pembayaran, 4, INSTR(a.tanggal_pembayaran, '-')+2) AS tahun,
							SUBSTR(a.tanggal_pembayaran, 0, INSTR(a.tanggal_pembayaran, '-')-1) AS bulan,
							concat(b.nama_bulan,REPLACE(SUBSTR(a.tanggal_pembayaran, 4, INSTR(a.tanggal_pembayaran, '-')+2), '-',b.nama_bulan)) as periode_pembayaran
					FROM	pro_tagihan_sewa a
					LEFT JOIN pro_nama_bulan b ON a.id_bulan = b.id_bulan
					WHERE	(SUBSTR(a.tanggal_pembayaran, 4, INSTR(a.tanggal_pembayaran, '-')+2) = '$tahun' AND SUBSTR(a.tanggal_pembayaran, 0, INSTR(a.tanggal_pembayaran, '-')-1) >='$bulan_dari_new') AND
							(SUBSTR(a.tanggal_pembayaran, 4, INSTR(a.tanggal_pembayaran, '-')+2) = '$tahun' AND SUBSTR(a.tanggal_pembayaran, 0, INSTR(a.tanggal_pembayaran, '-')-1) <='$bulan_sampai') AND
							a.status_bayar ='Sudah Bayar' AND 
							(UPPER(a.no_tagihan_sewa) LIKE '%".strtoupper(post('keyword'))."%'
							OR UPPER(a.nama_tenant) LIKE '%".strtoupper(post('keyword'))."%'
							OR UPPER(a.no_toko) LIKE '%".strtoupper(post('keyword'))."%'
							OR UPPER(a.jenis_usaha) LIKE '%".strtoupper(post('keyword'))."%'
							OR UPPER(a.lokasi_tempat) LIKE '%".strtoupper(post('keyword'))."%'
							OR UPPER(a.harga_sewa) LIKE '%".strtoupper(post('keyword'))."%'
							OR UPPER(a.tanggal_pembayaran) LIKE '%".strtoupper(post('keyword'))."%'
							OR UPPER(a.status_bayar) LIKE '%".strtoupper(post('keyword'))."%')
							ORDER BY ".(post('sort')=='' ? 'a.no_tagihan_sewa' : post('sort'))." ".(post('order')=='' ? 'asc' : post('order'));		
	
		$ls_sql2	= "	SELECT 	COUNT(1)
					    FROM 	pro_tagihan_sewa
						WHERE	(SUBSTR(tanggal_pembayaran, 4, INSTR(tanggal_pembayaran, '-')+2) = '$tahun' AND SUBSTR(tanggal_pembayaran, 0, INSTR(tanggal_pembayaran, '-')-1) >='$bulan_dari_new') AND
								(SUBSTR(tanggal_pembayaran, 4, INSTR(tanggal_pembayaran, '-')+2) = '$tahun' AND SUBSTR(tanggal_pembayaran, 0, INSTR(tanggal_pembayaran, '-')-1) <='$bulan_sampai') AND
								status_bayar ='Sudah Bayar' AND (UPPER(no_tagihan_sewa) LIKE '%".strtoupper(post('keyword'))."%'
								OR UPPER(nama_tenant) LIKE '%".strtoupper(post('keyword'))."%'
								OR UPPER(no_toko) LIKE '%".strtoupper(post('keyword'))."%'
								OR UPPER(jenis_usaha) LIKE '%".strtoupper(post('keyword'))."%'
								OR UPPER(lokasi_tempat) LIKE '%".strtoupper(post('keyword'))."%'
								OR UPPER(harga_sewa) LIKE '%".strtoupper(post('keyword'))."%'
								OR UPPER(tanggal_pembayaran) LIKE '%".strtoupper(post('keyword'))."%'
								OR UPPER(status_bayar) LIKE '%".strtoupper(post('keyword'))."%')
								ORDER BY ".(post('sort')=='' ? 'no_tagihan_sewa' : post('sort'))." ".(post('order')=='' ? 'asc' : post('order'));		
		
		$total = $this->get_data($ls_sql2);

		$result = $this->db->query($ls_sql);

		$data_p = array(	'rows'=> $result->result_array(), 
								'total' => $total);

		$date = date('Y-m-d');

		//load our new PHPExcel library
		$this->load->library('excel');
		//activate worksheet number 1
		$this->excel->setActiveSheetIndex(0);
		//name the worksheet
		$this->excel->getActiveSheet()->setTitle("Total Pendapatan_".$date);

		

			
		if ($data_p) {

			$styleArrayBorder = array(
				'borders' => array(
					'allborders' => array(
					'style' => PHPExcel_Style_Border::BORDER_THIN
					)
				)
			);

			$styleArrayItalic = array(
			 'font' => array(
			 'name' => 'Calibri',
			 'size' => 11,
			 'italic' => true,
			 'bold' => true,
			 )
			);

			$this->excel->getActiveSheet()->setCellValue('B8', 'No Tagihan Sewa');
			$this->excel->getActiveSheet()->setCellValue('C8', 'Tanggal Pembayaran');
			$this->excel->getActiveSheet()->setCellValue('D8', 'No Bukti Pembayaran');
			$this->excel->getActiveSheet()->setCellValue('E8', 'Nama Tenant');
			$this->excel->getActiveSheet()->setCellValue('F8', 'No Toko');
			$this->excel->getActiveSheet()->setCellValue('G8', 'Jenis Usaha');
			$this->excel->getActiveSheet()->setCellValue('H8', 'Lokasi Tempat');
			$this->excel->getActiveSheet()->setCellValue('I8', 'Periode Pembayaran');
			$this->excel->getActiveSheet()->setCellValue('J8', 'Harga Sewa');
			$this->excel->getActiveSheet()->setCellValue('K8', 'Staus Bayar');
			$this->excel->getActiveSheet()->setCellValue('L8', 'Keterangan');
			
			$this->excel->getActiveSheet()->getStyle('B8:L8')->getFont()->setBold(true);
			$this->excel->getActiveSheet()->getStyle('B8:L8')->getFill()->applyFromArray(array('type' => PHPExcel_Style_Fill::FILL_SOLID,'startcolor' => array('rgb' => 'B2B2B2')));
			$this->excel->getActiveSheet()->getStyle('B8:L8')->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_CENTER);

			$x = 8;
			$y= $x + 5;
			$z= $y + 1;

			for($i=0;$i<=$data_p['total']-1;$i++){
				$x++;
				$y++;
				$z++;

				$rows = $data_p['rows'];
				$rows2 = $rows[$i];

				$this->excel->getActiveSheet()->setCellValue('B'.$x, $rows2['no_tagihan_sewa']);
				$this->excel->getActiveSheet()->setCellValue('C'.$x, $rows2['tanggal_bayar']);
				$this->excel->getActiveSheet()->getStyle('B'.$x.':C'.$x)->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
				$this->excel->getActiveSheet()->setCellValue('D'.$x, $rows2['no_bukti_pembayaran']);
				$this->excel->getActiveSheet()->setCellValue('E'.$x, $rows2['nama_tenant']);
				$this->excel->getActiveSheet()->getStyle('D'.$x.':E'.$x)->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_LEFT);
				$this->excel->getActiveSheet()->setCellValue('F'.$x, $rows2['no_toko']);
				$this->excel->getActiveSheet()->getStyle('F'.$x)->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
				$this->excel->getActiveSheet()->setCellValue('G'.$x, $rows2['jenis_usaha']);
				$this->excel->getActiveSheet()->setCellValue('H'.$x, $rows2['lokasi_tempat']);
				$this->excel->getActiveSheet()->setCellValue('I'.$x, $rows2['periode_pembayaran']);
				$this->excel->getActiveSheet()->getStyle('G'.$x.':I'.$x)->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_LEFT);
				$this->excel->getActiveSheet()->setCellValue('J'.$x, $rows2['harga_sewa']);
				$this->excel->getActiveSheet()->getStyle('J'.$x)->getNumberFormat()->setFormatCode("Rp #,##0");
				$this->excel->getActiveSheet()->getStyle('J'.$x)->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_RIGHT);
				$this->excel->getActiveSheet()->setCellValue('K'.$x, $rows2['status_bayar']);
				$this->excel->getActiveSheet()->getStyle('K'.$x)->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
				$this->excel->getActiveSheet()->setCellValue('L'.$x, $rows2['keterangan']);
				$this->excel->getActiveSheet()->getStyle('L'.$x)->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_LEFT);

				$this->excel->getActiveSheet()->setCellValue('B4', strtoupper("Laporan Pendapatan Sewa ".$rows2['status_bayar']));
				$this->excel->getActiveSheet()->setCellValue('B5', $rows2['periode_pembayaran']);	


			}
				$query = $this->db->query(" SELECT  SUM(harga_sewa) as harga_sewa
													
											FROM 	pro_tagihan_sewa
											WHERE   (SUBSTR(tanggal_pembayaran, 4, INSTR(tanggal_pembayaran, '-')+2) = '$tahun' AND SUBSTR(tanggal_pembayaran, 0, INSTR(tanggal_pembayaran, '-')-1) >='$bulan_dari_new') AND
													(SUBSTR(tanggal_pembayaran, 4, INSTR(tanggal_pembayaran, '-')+2) = '$tahun' AND SUBSTR(tanggal_pembayaran, 0, INSTR(tanggal_pembayaran, '-')-1) <='$bulan_sampai') AND
													status_bayar = 'Sudah Bayar'");
				$total_sum = $query->row_array();

				$this->excel->getActiveSheet()->setCellValue('I'.$y, 'Total Pendapatan Sewa Sebesar');
				$this->excel->getActiveSheet()->getStyle('I'.$y)->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_RIGHT);
				$this->excel->getActiveSheet()->setCellValue('J'.$y, $total_sum['harga_sewa']);
				$this->excel->getActiveSheet()->getStyle('J'.$y)->getNumberFormat()->setFormatCode("Rp #,##0");
				$this->excel->getActiveSheet()->getStyle('J'.$y)->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_RIGHT);
				$this->excel->getActiveSheet()->getStyle('I'.$y)->applyFromArray($styleArrayItalic);
				$this->excel->getActiveSheet()->setCellValue('I'.$z, '( '.$this->toTerbilang($total_sum['harga_sewa']).' Rupiah )');
				$this->excel->getActiveSheet()->getStyle('I'.$z)->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_RIGHT);
				$this->excel->getActiveSheet()->getStyle('I'.$z)->applyFromArray($styleArrayItalic);

		}

		$styleArray = array(
			'borders' => array(
			    'allborders' => array(
			    'style' => PHPExcel_Style_Border::BORDER_THIN
			    )
			),
			'font'  => array(
			    'size'  => 9,
			    'name'  => 'verdana'
			)
		);

		$this->excel->getActiveSheet()->getStyle('B8:L'.$x)->applyFromArray($styleArray);
		unset($styleArray);

		$styleArray1 = array(
		    'font'  => array(
		    'bold'  => true,
		    'uppercase' => true,
		    'size'  => 11,
		    'name'  => 'Calibri'
		    )
		);

		$this->excel->getActiveSheet()->getColumnDimension('B')->setWidth(22);	
		$this->excel->getActiveSheet()->getColumnDimension('C')->setWidth(22);
		$this->excel->getActiveSheet()->getColumnDimension('D')->setWidth(22);
		$this->excel->getActiveSheet()->getColumnDimension('E')->setWidth(60);
		$this->excel->getActiveSheet()->getColumnDimension('F')->setWidth(22);
		$this->excel->getActiveSheet()->getColumnDimension('G')->setWidth(60);
		$this->excel->getActiveSheet()->getColumnDimension('H')->setWidth(22);
		$this->excel->getActiveSheet()->getColumnDimension('I')->setWidth(22);
		$this->excel->getActiveSheet()->getColumnDimension('J')->setWidth(27);
		$this->excel->getActiveSheet()->getColumnDimension('K')->setWidth(22);
		$this->excel->getActiveSheet()->getColumnDimension('L')->setWidth(22);

	/*	$this->excel->getActiveSheet()->getStyle('D1:E'.$this->excel->getActiveSheet()->getHighestRow())->getNumberFormat()->setFormatCode('#,##0.00'); 

		$this->excel->getActiveSheet()->getStyle('C1:C'.$this->excel->getActiveSheet()->getHighestRow())
    	->getAlignment()->setWrapText(true);
    	$this->excel->getActiveSheet()->getStyle('E1:E'.$this->excel->getActiveSheet()->getHighestRow())
    	->getAlignment()->setWrapText(true);*/

		//set aligment to center for that merged cell (A1 to D1)
		// $this->excel->getActiveSheet()->getStyle('B1:B2')->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
		$this->excel->getActiveSheet()->getStyle('B4:B5')->getFont()->setBold(true);

		//$filename= 'Laporan Tagihan Sewa_'.$rows2['tanggal_pembayaran'] .'.xls'; //save our workbook as this file name
		$filename= 'Laporan Pendapatan Sewa_'.$date.'.xls'; //save our workbook as this file name
		
		header('Content-Type: application/vnd.ms-excel'); //mime type
		header('Content-Disposition: attachment;filename="'.$filename.'"'); //tell browser what's the file name
		header('Cache-Control: max-age=0'); //no cache
			             
		//save it to Excel5 format (excel 2003 .XLS file), change this to 'Excel2007' (and adjust the filename extension, also the header mime type)
		//if you want to save it as .XLSX Excel 2007 format
		$objWriter = PHPExcel_IOFactory::createWriter($this->excel, 'Excel5');  
		//force user to download the Excel file without writing it to server's HD
		$objWriter->save('php://output');
	}


	function tagihan_sewa_satuan()
	{
		$id_tagihan=get('no_tagihan_sewa');
		$x=0;

		$ls_sql	= " SELECT	a.no_tagihan_sewa,a.nama_tenant,a.no_toko,
							a.jenis_usaha,a.lokasi_tempat,a.harga_sewa,
							a.tanggal_pembayaran,a.status_bayar,
							a.keterangan,TO_CHAR(a.tanggal_bayar,'DD/MM/YYYY') tanggal_bayar,
							a.no_bukti_pembayaran, b.nama_bulan, b.id_bulan,
							SUBSTR(a.tanggal_pembayaran, 4, INSTR(a.tanggal_pembayaran, '-')+2) AS tahun,
							SUBSTR(a.tanggal_pembayaran, 0, INSTR(a.tanggal_pembayaran, '-')-1) AS bulan,
							concat(b.nama_bulan,REPLACE(SUBSTR(a.tanggal_pembayaran, 4, INSTR(a.tanggal_pembayaran, '-')+2), '-',b.nama_bulan)) as periode_pembayaran
					FROM	pro_tagihan_sewa a
					LEFT JOIN pro_nama_bulan b ON a.id_bulan = b.id_bulan
					WHERE	UPPER(a.no_tagihan_sewa)='$id_tagihan' AND
							(UPPER(a.no_tagihan_sewa) LIKE '%".strtoupper(post('keyword'))."%'
							OR UPPER(a.nama_tenant) LIKE '%".strtoupper(post('keyword'))."%'
							OR UPPER(a.no_toko) LIKE '%".strtoupper(post('keyword'))."%'
							OR UPPER(a.jenis_usaha) LIKE '%".strtoupper(post('keyword'))."%'
							OR UPPER(a.lokasi_tempat) LIKE '%".strtoupper(post('keyword'))."%'
							OR UPPER(a.harga_sewa) LIKE '%".strtoupper(post('keyword'))."%'
							OR UPPER(a.tanggal_pembayaran) LIKE '%".strtoupper(post('keyword'))."%'
							OR UPPER(a.status_bayar) LIKE '%".strtoupper(post('keyword'))."%')
							ORDER BY ".(post('sort')=='' ? 'a.no_tagihan_sewa' : post('sort'))." ".(post('order')=='' ? 'asc' : post('order'));	
	
		$ls_sql2	= "	SELECT 	COUNT(1)
						FROM	pro_tagihan_sewa a
						LEFT JOIN pro_nama_bulan b ON a.id_bulan = b.id_bulan	
					    WHERE	UPPER(a.no_tagihan_sewa)='$id_tagihan' AND
								(UPPER(a.no_tagihan_sewa) LIKE '%".strtoupper(post('keyword'))."%'
								OR UPPER(a.nama_tenant) LIKE '%".strtoupper(post('keyword'))."%'
								OR UPPER(a.no_toko) LIKE '%".strtoupper(post('keyword'))."%'
								OR UPPER(a.jenis_usaha) LIKE '%".strtoupper(post('keyword'))."%'
								OR UPPER(a.lokasi_tempat) LIKE '%".strtoupper(post('keyword'))."%'
								OR UPPER(a.harga_sewa) LIKE '%".strtoupper(post('keyword'))."%'
								OR UPPER(a.tanggal_pembayaran) LIKE '%".strtoupper(post('keyword'))."%'
								OR UPPER(a.status_bayar) LIKE '%".strtoupper(post('keyword'))."%')
								ORDER BY ".(post('sort')=='' ? 'a.no_tagihan_sewa' : post('sort'))." ".(post('order')=='' ? 'asc' : post('order'));	
		
		$total = $this->get_data($ls_sql2);

		$result = $this->db->query($ls_sql);

		$data_p = array(	'rows'=> $result->result_array(), 
								'total' => $total);

		$date = date('d M Y');

		//load our new PHPExcel library
		$this->load->library('excel');
		//activate worksheet number 1
		$this->excel->setActiveSheetIndex(0);
		//name the worksheet
		$this->excel->getActiveSheet()->setTitle("Laporan Tagihan Sewa");

		$no = 1;

		/*$objDrawing = new PHPExcel_Worksheet_Drawing();
			$objDrawing->setName('Logo');
			$objDrawing->setDescription('Logo');
			$objDrawing->setPath('http://localhost/primkokas-new/files/logo_report.png');
			$objDrawing->setCoordinates('B1');
			$objDrawing->setHeight(36);*/
			
			/*$objPHPExcel = new PHPExcel();
			$sheet = $objPHPExcel->setSheetIndexAndTitle(1, "YOUR_SHEET_TITLE"); // first sheet
			$objDrawing = new PHPExcel_Worksheet_Drawing();
			$objDrawing->setName('Logo');
			$objDrawing->setDescription('Logo');
			$logo = base_path() . '/images/logo.png'; // Provide path to your logo file
			$objDrawing->setPath($logo);
			$objDrawing->setOffsetX(8);    // setOffsetX works properly
			$objDrawing->setOffsetY(300);  //setOffsetY has no effect
			$objDrawing->setCoordinates('B1');
			$objDrawing->setHeight(75); // logo height
			$objDrawing->setWorksheet($sheet);*/ 

		if ($data_p) {

			$styleArrayBorder = array(
				'borders' => array(
					'allborders' => array(
					'style' => PHPExcel_Style_Border::BORDER_THIN
					)
				)
			);

			$styleArrayUnderline = array(
			 'font' => array(
			 'underline' => PHPExcel_Style_Font::UNDERLINE_SINGLE,
			 'name' => 'Calibri',
			 'size' => 11,
			 'bold' => true
			 )
			);

			$styleArrayDefault = array(
			 'font' => array(
			 'name' => 'Calibri',
			 'size' => 11,
			 )
			);

			$styleArrayItalic = array(
			 'font' => array(
			 'name' => 'Calibri',
			 'size' => 11,
			 'italic' => true
			 )
			);

			$styleArrayFont = array(
			 'font' => array(
			 'name' => 'Calibri',
			 'size' => 9,
			 'color' => array('rgb' => 'FF4719'),
			 )
			);

			$styleArrayFont1 = array(
			 'font' => array(
			 'name' => 'Calibri',
			 'size' => 9,
			 'color' => array('rgb' => '1919FF'),
			 )
			);

			$rows = $data_p['rows'];
			$rows2 = $rows[0];


			$this->excel->getActiveSheet()->setCellValue('J1', 'PRIMER KOPERASI KARYAWAN KRAKATAU STEEL');
			$this->excel->getActiveSheet()->getStyle('J1')->applyFromArray($styleArrayFont);
			$this->excel->getActiveSheet()->getStyle('J1')->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_RIGHT);

			$this->excel->getActiveSheet()->setCellValue('J2', 'Gedung Krakatau Junction Lt. 3, Jl. KH. Yasin Neji Komp. PT KS');
			$this->excel->getActiveSheet()->setCellValue('J3', 'Cilegon - Banten 42435');
			$this->excel->getActiveSheet()->setCellValue('J4', 'Phone +62 (254) 392784, 372289 Fax. + (254) 372290, 398884');
			$this->excel->getActiveSheet()->setCellValue('J5', 'Website : www.primkokas.co.id');
			$this->excel->getActiveSheet()->setCellValue('J6', 'email: info@primkokas.co.id');
			$this->excel->getActiveSheet()->getStyle('J2:J6')->applyFromArray($styleArrayFont1);
			$this->excel->getActiveSheet()->getStyle('J2:J6')->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_RIGHT);

			$this->excel->getActiveSheet()->setCellValue('A8', 'Nomor');
			$this->excel->getActiveSheet()->setCellValue('A9', 'Lampiran');
			$this->excel->getActiveSheet()->setCellValue('A10', 'Perihal');
			$this->excel->getActiveSheet()->getStyle('A10')->getFont()->setBold(true);

			$this->excel->getActiveSheet()->setCellValue('B8', ':' );
			$this->excel->getActiveSheet()->setCellValue('C8', $rows2['no_tagihan_sewa']);
			$this->excel->getActiveSheet()->setCellValue('C9', '1 (satu) set.');
			$this->excel->getActiveSheet()->setCellValue('C10', 'Konfirmasi Tagihan');

			$this->excel->getActiveSheet()->getStyle('C10')->applyFromArray($styleArrayUnderline);
			$this->excel->getActiveSheet()->setCellValue('C12', 'Kepada Yth.');
			$this->excel->getActiveSheet()->setCellValue('C13', 'Bapak/Ibu '.$rows2['nama_tenant']);
			$this->excel->getActiveSheet()->getStyle('C13')->getFont()->setBold(true);

			$this->excel->getActiveSheet()->setCellValue('C14',  $rows2['lokasi_tempat'].'No. '.$rows2['no_toko']);
			$this->excel->getActiveSheet()->setCellValue('C15', 'Di');
			$this->excel->getActiveSheet()->setCellValue('D16', 'Tempat');
			$this->excel->getActiveSheet()->setCellValue('C18', 'Dengan Hormat');

			$this->excel->getActiveSheet()->setCellValue('C20', 'Puji syukur ke hadirat Allah SWT teriring doa semoga Bapak/Ibu dalam keadaan ');
			$this->excel->getActiveSheet()->setCellValue('C21', 'sehat wal afiat dan senantiasa mendapat lindungan-Nya di dalam menjalankan');
			$this->excel->getActiveSheet()->setCellValue('C22', 'tugas sehari-hari. Amin.');

			$this->excel->getActiveSheet()->setCellValue('C24', 'Bersama ini kami selaku Pihak Property Management ingin menyampaikan');
			$this->excel->getActiveSheet()->setCellValue('C25', 'informasi bahwa Bapak/Ibu ' .$rows2['nama_tenant']. ' belum menyelesaikan tagihan sewa toko ' .$rows2['no_toko']. ' untuk');
			$this->excel->getActiveSheet()->setCellValue('C26', 'periode ' .$rows2['periode_pembayaran']. ' yaitu sebagai berikut:');

			$this->excel->getActiveSheet()->setCellValue('C28', '1.');
			$this->excel->getActiveSheet()->setCellValue('D28', 'Tagihan Sewa');
			$this->excel->getActiveSheet()->getStyle('C28:D28')->getFont()->setBold(true);

			$this->excel->getActiveSheet()->setCellValue('C29', '-');
			$this->excel->getActiveSheet()->setCellValue('D29', 'Periode ' .$rows2['periode_pembayaran']);
			$this->excel->getActiveSheet()->setCellValue('G29', '@ Rp.');
			$this->excel->getActiveSheet()->setCellValue('H29',  $rows2['harga_sewa']);
			$this->excel->getActiveSheet()->setCellValue('C31', 'Total Keseluruhan yang harus di bayar');

			$this->excel->getActiveSheet()->setCellValue('G31', '@ Rp.');
			$this->excel->getActiveSheet()->setCellValue('H31', $rows2['harga_sewa']);
			$this->excel->getActiveSheet()->getStyle('C31:H31')->getFont()->setBold(true);
			$this->excel->getActiveSheet()->setCellValue('C32', "( ".$this->toTerbilang($rows2['harga_sewa'])." Rupiah )");
			$this->excel->getActiveSheet()->getStyle('C32')->applyFromArray($styleArrayItalic);
			$this->excel->getActiveSheet()->getStyle('H29')->getNumberFormat()->setFormatCode('Rp #,##0'); 
			$this->excel->getActiveSheet()->getStyle('H31')->getNumberFormat()->setFormatCode('Rp #,##0'); 

			$this->excel->getActiveSheet()->setCellValue('C34', 'Kami harapkan Bapak/Ibu dapat segera menyelesaikan tagihan tersebut sesuai ');
			$this->excel->getActiveSheet()->setCellValue('C35', 'syarat dan ketentuan yang berlaku.');
			$this->excel->getActiveSheet()->setCellValue('C36', 'Demikian pemberitahuan ini kami sampaikan, atas perhatian dan kerjasamanya');
			$this->excel->getActiveSheet()->setCellValue('C37', 'diucapkan terima kasih.');

			$this->excel->getActiveSheet()->setCellValue('E40', 'Mengetahui,');
			$this->excel->getActiveSheet()->setCellValue('E45', 'Aan Supriana');
			$this->excel->getActiveSheet()->setCellValue('E46', 'Internal Busines & Property Div. Manager');

			$this->excel->getActiveSheet()->setCellValue('H39', 'Cilegon, '.$date);
			$this->excel->getActiveSheet()->setCellValue('H40', 'PRIMER KOPERASI KARYAWAN');
			$this->excel->getActiveSheet()->setCellValue('H41', 'KRAKATAU STEEL');
				

			$this->excel->getActiveSheet()->setCellValue('H45', 'Ngajito');
			$this->excel->getActiveSheet()->setCellValue('H46', 'Property Div.');

			$this->excel->getActiveSheet()->setCellValue('C48', 'Tembusan :');
			$this->excel->getActiveSheet()->setCellValue('D49', '1. Yth. Ketua Umun PRIMKOKAS');
			$this->excel->getActiveSheet()->setCellValue('D50', '2. Arsip');

			$this->excel->getActiveSheet()->getStyle('E45:I45')->applyFromArray($styleArrayUnderline);
			$this->excel->getActiveSheet()->getStyle('E39:I46')->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_CENTER);

		}

		$this->excel->getActiveSheet()->getColumnDimension('A')->setWidth(8.4);
		$this->excel->getActiveSheet()->getColumnDimension('B')->setWidth(0.7);
		$this->excel->getActiveSheet()->getColumnDimension('C')->setWidth(0.7);
		$this->excel->getActiveSheet()->getColumnDimension('D')->setWidth(8.5);
		$this->excel->getActiveSheet()->getColumnDimension('E')->setWidth(15.5);
		$this->excel->getActiveSheet()->getColumnDimension('F')->setWidth(9.4);
		$this->excel->getActiveSheet()->getColumnDimension('G')->setWidth(12);
		$this->excel->getActiveSheet()->getColumnDimension('I')->setWidth(1);
		$this->excel->getActiveSheet()->getColumnDimension('H')->setWidth(18);
		$this->excel->getActiveSheet()->getRowDimension('7')->setRowHeight(3);
		$this->excel->getActiveSheet()->getRowDimension('30')->setRowHeight(3);
		$this->excel->getActiveSheet()->getRowDimension('33')->setRowHeight(3);
		$this->excel->getActiveSheet()->getRowDimension('38')->setRowHeight(3);

/*
		$this->excel->getActiveSheet()->getStyle('D1:C'.$this->excel->getActiveSheet()->getHighestRow())->getNumberFormat()->setFormatCode('#,##0.00'); 

		$this->excel->getActiveSheet()->getStyle('C1:C'.$this->excel->getActiveSheet()->getHighestRow())
    	->getAlignment()->setWrapText(true);
    	$this->excel->getActiveSheet()->getStyle('G1:G'.$this->excel->getActiveSheet()->getHighestRow())
    	->getAlignment()->setWrapText(true);*/

		//set aligment to center for that merged cell (A1 to D1)
		// $this->excel->getActiveSheet()->getStyle('B1:B2')->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
		//$this->excel->getActiveSheet()->getStyle('B4:B5')->getFont()->setBold(true);

		$filename= 'Laporan Tagihan Sewa_'.$rows2['no_tagihan_sewa'].'.xls'; //save our workbook as this file name
		header('Content-Type: application/vnd.ms-excel'); //mime type
		header('Content-Disposition: attachment;filename="'.$filename.'"'); //tell browser what's the file name
		header('Cache-Control: max-age=0'); //no cache
			             
		//save it to Excel5 format (excel 2003 .XLS file), change this to 'Excel2007' (and adjust the filename extension, also the header mime type)
		//if you want to save it as .XLSX Excel 2007 format
		$objWriter = PHPExcel_IOFactory::createWriter($this->excel, 'Excel5');  
		//force user to download the Excel file without writing it to server's HD
		$objWriter->save('php://output');
	}

	function permintaan_pembayaran()
		{

			$id=get('id_pembayaran');
			$x=0;

			$ls_sql	= " SELECT	no_pembayaran,id_pembayaran,
								TO_CHAR(tanggal_bayar,'DD/MM/YYYY') tanggal_bayar,
								keterangan
						FROM	pro_permintaan_pembayaran
						WHERE	id_pembayaran = '$id' AND (UPPER(id_pembayaran) LIKE '%".strtoupper(post('keyword'))."%'
								OR UPPER(no_pembayaran) LIKE '%".strtoupper(post('keyword'))."%')
						ORDER BY ".(post('sort')=='' ? 'id_pembayaran' : post('sort'))." ".(post('order')=='' ? 'asc' : post('order'));	
			
			$ls_sql2	= "	SELECT COUNT(1)
							FROM	pro_permintaan_pembayaran
							WHERE	id_pembayaran = '$id' AND (UPPER(id_pembayaran) LIKE '%".strtoupper(post('keyword'))."%'
									OR UPPER(no_pembayaran) LIKE '%".strtoupper(post('keyword'))."%')
							ORDER BY ".(post('sort')=='' ? 'id_pembayaran' : post('sort'))." ".(post('order')=='' ? 'asc' : post('order'));	
			
			$total = $this->get_data($ls_sql2);

			$result = $this->db->query($ls_sql);

			$data_p = array(	'rows'=> $result->result_array(), 
									'total' => $total);

			$ls_sql3	= " SELECT	id_pembayaran,id_pembayaran_detail,
								harga_satuan,banyak_satuan,total,
								keterangan_uraian
						FROM	pro_permintaan_pembayaran_dtl
						WHERE	id_pembayaran = '$id' AND (UPPER(id_pembayaran) LIKE '%".strtoupper(post('keyword'))."%'
								OR UPPER(banyak_satuan) LIKE '%".strtoupper(post('keyword'))."%')
						ORDER BY ".(post('sort')=='' ? 'id_pembayaran_detail' : post('sort'))." ".(post('order')=='' ? 'asc' : post('order'));
				
			$ls_sql4	= "	SELECT COUNT(1)
							FROM	pro_permintaan_pembayaran_dtl
							WHERE	id_pembayaran = '$id' AND (UPPER(id_pembayaran) LIKE '%".strtoupper(post('keyword'))."%'
									OR UPPER(banyak_satuan) LIKE '%".strtoupper(post('keyword'))."%')
							ORDER BY ".(post('sort')=='' ? 'id_pembayaran_detail' : post('sort'))." ".(post('order')=='' ? 'asc' : post('order'));	
					
			$totald = $this->get_data($ls_sql4);

			$resultd = $this->db->query($ls_sql3);

			$data_p1 = array(	'rowsd'=> $resultd->result_array(), 
									'totald' => $totald);

			$date = date('Y-m-d');

			//load our new PHPExcel library
			$this->load->library('excel');




			//activate worksheet number 1
			$this->excel->setActiveSheetIndex(0);
			// Set Orientation, size and scaling
			$this->excel->setActiveSheetIndex(0);
			$this->excel->getActiveSheet()->getPageSetup()->setOrientation(PHPExcel_Worksheet_PageSetup::ORIENTATION_PORTRAIT);
			$this->excel->getActiveSheet()->getPageSetup()->setPaperSize(PHPExcel_Worksheet_PageSetup::PAPERSIZE_A4);
			$this->excel->getActiveSheet()->getPageSetup()->setFitToPage(true);
			$this->excel->getActiveSheet()->getPageSetup()->setFitToWidth(1);
			$this->excel->getActiveSheet()->getPageSetup()->setFitToHeight(0);
			//name the worksheet
			$this->excel->getActiveSheet()->setTitle("Permintaan Pembayaran".$date);

			
			if ($data_p) {

			$styleArrayBorder = array(
				'borders' => array(
					'allborders' => array(
					'style' => PHPExcel_Style_Border::BORDER_THIN
					)
				)
			);

			$styleArrayBorder1 = array(
				'borders' => array(
					'allborders' => array(
					'style' => PHPExcel_Style_Border::BORDER_THIN
					)
				)
			);

			$styleArrayUnderline = array(
			 'font' => array(
			 'underline' => PHPExcel_Style_Font::UNDERLINE_SINGLE,
			 'name' => 'Calibri',
			 'size' => 11,
			 'bold' => true
			 )
			);

			$styleArrayDefault = array(
			 'font' => array(
			 'name' => 'Calibri',
			 'size' => 11,
			 )
			);

			$styleArraySpecial = array(
			 'font' => array(
			 'name' => 'Calibri',
			 'size' => 18,
			 )
			);

			$styleArrayItalic = array(
			 'font' => array(
			 'name' => 'Calibri',
			 'size' => 11,
			 'italic' => true
			 )
			);

			$styleArrayFont = array(
			 'font' => array(
			 'name' => 'Calibri',
			 'size' => 9,
			 'color' => array('rgb' => 'FF4719'),
			 )
			);

			$styleArrayFont1 = array(
			 'font' => array(
			 'name' => 'Calibri',
			 'size' => 9,
			 'color' => array('rgb' => '1919FF'),
			 )
			);

			$styleArrayTerbilang = array(
			 'font' => array(
			 'name' => 'Calibri',
			 'size' => 11,
			 'italic' => true,
			 'bold' => true
			 )
			);

			$rows = $data_p['rows'];
			$rows2 = $rows[0];

			//	$this->excel->getActiveSheet()->setCellValue('A3', 'logo primkokas');
			// Add a drawing to the worksheet
			$objDrawing = new PHPExcel_Worksheet_Drawing();
			$objDrawing->setName('Logo');
			$objDrawing->setDescription('Logo');
			$objDrawing->setPath(APPPATH.'file/media/logo_primkokas.jpg');
			$objDrawing->setCoordinates('A1');
			//$objDrawing->setHeight(120);
			//$objDrawing->setWidth(120);
			$objDrawing->setWorksheet($this->excel->getActiveSheet());
        	// $this->excel->getActiveSheet()->setCellValue('A3')->setPath('file/media/logo_primkokas.jpg');
			$this->excel->getActiveSheet()->setCellValue('G1', 'PRIMER KOPERASI KARYAWAN KRAKATAU STEEL');
			$this->excel->getActiveSheet()->setCellValue('G2', 'Gedung Krakatau Junction, Jl. KH. Yasin Beji Komp.');
			$this->excel->getActiveSheet()->setCellValue('G3', 'PTKS');
			$this->excel->getActiveSheet()->setCellValue('G4', 'Cilegon-Banten 42435');
			$this->excel->getActiveSheet()->setCellValue('G5', 'Telp.(0254) 392784, 372289 Fax. (0254) 372290');
			$this->excel->getActiveSheet()->setCellValue('G6', 'Website : www.primkokas.co.id');
			$this->excel->getActiveSheet()->setCellValue('G7', 'Email : info@primkokas.co.id');
			$this->excel->getActiveSheet()->getStyle('G2:G7')->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_LEFT);

			$this->excel->getActiveSheet()->setCellValue('A9', 'PRIMKOKAS');
			$this->excel->getActiveSheet()->setCellValue('A10', 'PRIMER KOPERASI KARYAWAN KRAKATAU STEEL');
			$this->excel->getActiveSheet()->setCellValue('J10', 'PERMINTAAN PEMBAYARAN');
			$this->excel->getActiveSheet()->getStyle('J10:K10')->getBorders()->getTop()->setBorderStyle( PHPExcel_Style_Border::BORDER_THIN);
			$this->excel->getActiveSheet()->getStyle('J10:K10')->getBorders()->getBottom()->setBorderStyle( PHPExcel_Style_Border::BORDER_THIN);
			$this->excel->getActiveSheet()->setCellValue('J11', 'Nomor: '.$rows2['no_pembayaran']);
			$this->excel->getActiveSheet()->getStyle('A9:J10')->applyFromArray($styleArrayUnderline);
			$this->excel->getActiveSheet()->getStyle('A9:J10')->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_LEFT);
			$this->excel->getActiveSheet()->getStyle('A9')->applyFromArray($styleArraySpecial);


			$this->excel->getActiveSheet()->setCellValue('A18', 'NO.');
			$this->excel->getActiveSheet()->mergeCells('A18:A19');
			$this->excel->getActiveSheet()->setCellValue('B18', 'KETERANGAN / URAIAN');
			$this->excel->getActiveSheet()->getStyle('A18:B19')->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
			$this->excel->getActiveSheet()->mergeCells('B18:F19');
			$this->excel->getActiveSheet()->setCellValue('G18', 'BANYAKNYA');
			$this->excel->getActiveSheet()->mergeCells('G18:H18');
			$this->excel->getActiveSheet()->setCellValue('G19', 'SATUAN');
			$this->excel->getActiveSheet()->mergeCells('G19:H19');
			$this->excel->getActiveSheet()->setCellValue('I18', 'HARGA SATUAN');
			$this->excel->getActiveSheet()->mergeCells('I18:J18');
			$this->excel->getActiveSheet()->setCellValue('I19', '( Rp. )');
			$this->excel->getActiveSheet()->mergeCells('I19:J19');
			$this->excel->getActiveSheet()->setCellValue('K18', 'JUMLAH HARGA'); 
			$this->excel->getActiveSheet()->setCellValue('K19', '( Rp. )');
			$this->excel->getActiveSheet()->getStyle('A18:K19')->getFont()->setBold(true);
			$this->excel->getActiveSheet()->getStyle('A18:K19')->getFill()->applyFromArray(array('type' => PHPExcel_Style_Fill::FILL_SOLID,'startcolor' => array('rgb' => 'B2B2B2')));
			$this->excel->getActiveSheet()->getStyle('A18:K19')->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_CENTER);

			$tgl_old = str_replace("/", "", $rows2['tanggal_bayar']);

		    $tahun_new = substr($tgl_old, 4, 4);
		    $bulan_new = substr($tgl_old, 2, 2);
		    $hari_new   = substr($tgl_old, 0, 2);

		    $hasil = "";
		    $iromawi =
		    array("","Januari","Februari","Maret","April","Mei","Juni","Juli","Agustus","September","Oktober","November","Desember");
		    if(array_key_exists($bulan_new,$iromawi)){
		      $hasil = $iromawi[$bulan_new];
		    }
			
			$this->excel->getActiveSheet()->setCellValue('J30', 'Cilegon,'.$hari_new.' '.$hasil.' '.$tahun_new);
			$this->excel->getActiveSheet()->setCellValue('D31', 'MENYETUJUI,');
			$this->excel->getActiveSheet()->setCellValue('J31', 'PEMOHON');

			$this->excel->getActiveSheet()->setCellValue('D37', 'Aan Supriana');
			$this->excel->getActiveSheet()->setCellValue('D38', 'Internal Bussines & Property Manager');
			$this->excel->getActiveSheet()->setCellValue('J37', 'Ngatijo');
			$this->excel->getActiveSheet()->setCellValue('J38', 'Property Div');
			$this->excel->getActiveSheet()->getStyle('B30:J38')->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
			$this->excel->getActiveSheet()->getStyle('B30:J38')->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::VERTICAL_CENTER);
			$this->excel->getActiveSheet()->getStyle('B37:J37')->applyFromArray($styleArrayUnderline);
			$this->excel->getActiveSheet()->getStyle('B38:J38')->getFont()->setBold(true);

			$x = 20;

			for($i=0;$i<=$data_p1['totald']-1;$i++){
				$x++;

				$rows3 = $data_p1['rowsd'];
				$rows4 = $rows3[$i];

			$query = $this->db->query("SELECT SUM(total) as total FROM pro_permintaan_pembayaran_dtl WHERE id_pembayaran = '$id' ");
			$total_sum = $query->row_array();

			//bagian head//
			$this->excel->getActiveSheet()->setCellValue('A12', 'Harap diberikan Pembayaran sebesar  :');
			$this->excel->getActiveSheet()->setCellValue('F12', $total_sum['total']);
			$this->excel->getActiveSheet()->getStyle('F12')->getNumberFormat()->setFormatCode('Rp #,##0'); 

			$this->excel->getActiveSheet()->getStyle('F12')->getFont()->setBold(true);
			$this->excel->getActiveSheet()->setCellValue('A13', 'Terbilang :');
			$this->excel->getActiveSheet()->setCellValue('C13',  '# '.$this->toTerbilang($total_sum['total']).' Rupiah');
			$this->excel->getActiveSheet()->getStyle('C13')->applyFromArray($styleArrayTerbilang);
			$this->excel->getActiveSheet()->mergeCells('C13:K13');
			$this->excel->getActiveSheet()->getStyle('C13:K13')->applyFromArray($styleArrayBorder);
			$this->excel->getActiveSheet()->getStyle('C13:K13')->getFill()->applyFromArray(array('type' => PHPExcel_Style_Fill::FILL_SOLID,'startcolor' => array('rgb' => 'B2B2B2')));
			$this->excel->getActiveSheet()->setCellValue('A14', 'Untuk keperluan : '.$rows2['keterangan']);
			$this->excel->getActiveSheet()->getStyle('D14')->getFont()->setBold(true);
			$this->excel->getActiveSheet()->getStyle('A12:D14')->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_LEFT);
			//-------//

			$this->excel->getActiveSheet()->mergeCells('B20:F20');
			$this->excel->getActiveSheet()->mergeCells('B21:F21');
			$this->excel->getActiveSheet()->mergeCells('B22:F22');
			$this->excel->getActiveSheet()->mergeCells('B23:F23');
			$this->excel->getActiveSheet()->mergeCells('B24:F24');
			$this->excel->getActiveSheet()->mergeCells('B25:F25');
			$this->excel->getActiveSheet()->mergeCells('B26:F26');
			$this->excel->getActiveSheet()->mergeCells('B27:F27');

			$this->excel->getActiveSheet()->mergeCells('G20:H20');
			$this->excel->getActiveSheet()->mergeCells('G21:H21');
			$this->excel->getActiveSheet()->mergeCells('G22:H22');
			$this->excel->getActiveSheet()->mergeCells('G23:H23');
			$this->excel->getActiveSheet()->mergeCells('G24:H24');
			$this->excel->getActiveSheet()->mergeCells('G25:H25');
			$this->excel->getActiveSheet()->mergeCells('G26:H26');
			$this->excel->getActiveSheet()->mergeCells('G27:H27');

			$this->excel->getActiveSheet()->setCellValue('A'.$x, $rows4['id_pembayaran_detail']);
			$this->excel->getActiveSheet()->mergeCells('B'.$x.':F'.$x);
			$this->excel->getActiveSheet()->setCellValue('B'.$x, $rows4['keterangan_uraian']);
			$this->excel->getActiveSheet()->mergeCells('G'.$x.':H'.$x);
			$this->excel->getActiveSheet()->setCellValue('G'.$x, $rows4['banyak_satuan']);
			$this->excel->getActiveSheet()->getStyle('B'.$x.':F'.$x)->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_LEFT);
			$this->excel->getActiveSheet()->getStyle('G'.$x)->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
			$this->excel->getActiveSheet()->setCellValue('J'.$x, $rows4['harga_satuan']);
			$this->excel->getActiveSheet()->getStyle('J'.$x)->getNumberFormat()->setFormatCode('Rp #,##0'); 

			$this->excel->getActiveSheet()->setCellValue('K'.$x, $rows4['total']);
			$this->excel->getActiveSheet()->getStyle('K'.$x)->getNumberFormat()->setFormatCode('Rp #,##0'); 
			$this->excel->getActiveSheet()->getStyle('K'.$x.':J'.$x)->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_RIGHT);
			$this->excel->getActiveSheet()->setCellValue('A28', 'TOTAL');
			$this->excel->getActiveSheet()->setCellValue('K28', $total_sum['total']);
			$this->excel->getActiveSheet()->getStyle('A28:K28')->getFont()->setBold(true);
			$this->excel->getActiveSheet()->getStyle('K28')->getNumberFormat()->setFormatCode('Rp #,##0'); 
			$this->excel->getActiveSheet()->mergeCells('A28:J28');
			$this->excel->getActiveSheet()->getStyle('A28:J28')->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_RIGHT);

			}

			$styleArray = array(
			'borders' => array(
			    'allborders' => array(
			    'style' => PHPExcel_Style_Border::BORDER_THIN
			    )
			),
			'font'  => array(
			    'size'  => 9,
			    'name'  => 'verdana'
			)
		);

		$this->excel->getActiveSheet()->getStyle('A18:K28')->applyFromArray($styleArray);
			
		}

		$this->excel->getActiveSheet()->getColumnDimension('A')->setWidth(5.43);
		$this->excel->getActiveSheet()->getColumnDimension('B')->setWidth(5.43);
		$this->excel->getActiveSheet()->getColumnDimension('C')->setWidth(3.14);
		$this->excel->getActiveSheet()->getColumnDimension('D')->setWidth(17.71);
		$this->excel->getActiveSheet()->getColumnDimension('E')->setWidth(13.29);
		$this->excel->getActiveSheet()->getColumnDimension('F')->setWidth(19.86);
		$this->excel->getActiveSheet()->getColumnDimension('G')->setWidth(6.71);
		$this->excel->getActiveSheet()->getColumnDimension('H')->setWidth(8.86);
		$this->excel->getActiveSheet()->getColumnDimension('I')->setWidth(0);
		$this->excel->getActiveSheet()->getColumnDimension('J')->setWidth(15.57);
		$this->excel->getActiveSheet()->getColumnDimension('K')->setWidth(15.86);
		/*	$this->excel->getActiveSheet()->getStyle('D1:E'.$this->excel->getActiveSheet()->getHighestRow())->getNumberFormat()->setFormatCode('#,##0.00'); 

			$this->excel->getActiveSheet()->getStyle('C1:C'.$this->excel->getActiveSheet()->getHighestRow())
	    	->getAlignment()->setWrapText(true);
	    	$this->excel->getActiveSheet()->getStyle('E1:E'.$this->excel->getActiveSheet()->getHighestRow())
	    	->getAlignment()->setWrapText(true);*/

			//set aligment to center for that merged cell (A1 to D1)
			// $this->excel->getActiveSheet()->getStyle('B1:B2')->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
			$this->excel->getActiveSheet()->getStyle('B4:B5')->getFont()->setBold(true);

			$filename= 'Laporan Permintaan Pembayaran_'.$date.'.xls'; //save our workbook as this file name
			header('Content-Type: application/vnd.ms-excel'); //mime type
			header('Content-Disposition: attachment;filename="'.$filename.'"'); //tell browser what's the file name
			header('Cache-Control: max-age=0'); //no cache
			header('Content-Type: text/html; charset=utf-8');
				             
			//save it to Excel5 format (excel 2003 .XLS file), change this to 'Excel2007' (and adjust the filename extension, also the header mime type)
			//if you want to save it as .XLSX Excel 2007 format
			$objWriter = PHPExcel_IOFactory::createWriter($this->excel, 'Excel5');  
			//force user to download the Excel file without writing it to server's HD
			$objWriter->save('php://output');
		}

		function data_penyelenggara_all(){

		$status_tenant='Tenant';
		$tanggal=get('tanggal');
		$x=0;

		$ls_sql	= " SELECT	*
					FROM	pro_surat_penyelenggara
					WHERE	(UPPER(no_surat) LIKE '%".strtoupper(post('keyword'))."%'
							OR UPPER(nama_kegiatan) LIKE '%".strtoupper(post('keyword'))."%')
					ORDER BY ".(post('sort')=='' ? 'nama_kegiatan' : post('sort'))." ".(post('order')=='' ? 'asc' : post('order'));	
		
		$ls_sql2	= "	SELECT COUNT(1)
						FROM	pro_surat_penyelenggara
					   	WHERE	(UPPER(no_surat) LIKE '%".strtoupper(post('keyword'))."%'
							OR UPPER(nama_kegiatan) LIKE '%".strtoupper(post('keyword'))."%')
							ORDER BY ".(post('sort')=='' ? 'nama_kegiatan' : post('sort'))." ".(post('order')=='' ? 'asc' : post('order'));
		
		$total = $this->get_data($ls_sql2);

		$result = $this->db->query($ls_sql);

		$data_p = array(	'rows'=> $result->result_array(), 
								'total' => $total);

		$date = date('Y-m-d');

		//load our new PHPExcel library
		$this->load->library('excel');
		//activate worksheet number 1
		$this->excel->setActiveSheetIndex(0);
		//name the worksheet
		$this->excel->getActiveSheet()->setTitle("Data Surat Penyelenggara");

		

			
		if ($data_p) {

			$styleArrayBorder = array(
				'borders' => array(
					'allborders' => array(
					'style' => PHPExcel_Style_Border::BORDER_THIN
					)
				)
			);

			$this->excel->getActiveSheet()->setCellValue('B8', 'No Surat');
			$this->excel->getActiveSheet()->setCellValue('C8', 'Nama Penyelenggara');
			$this->excel->getActiveSheet()->setCellValue('D8', 'Alamat');
			$this->excel->getActiveSheet()->setCellValue('E8', 'Diwakili Oleh');
			$this->excel->getActiveSheet()->setCellValue('F8', 'No Telephone');
			
			
			$this->excel->getActiveSheet()->getStyle('B8:F8')->getFont()->setBold(true);
			$this->excel->getActiveSheet()->getStyle('B8:F8')->getFill()->applyFromArray(array('type' => PHPExcel_Style_Fill::FILL_SOLID,'startcolor' => array('rgb' => 'B2B2B2')));
			$this->excel->getActiveSheet()->getStyle('B8:F8')->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_CENTER);

			$x = 8;

			for($i=0;$i<=$data_p['total']-1;$i++){
				$x++;

				$rows = $data_p['rows'];
				$rows2 = $rows[$i];

				$this->excel->getActiveSheet()->setCellValue('B'.$x, $rows2['no_surat']);
				$this->excel->getActiveSheet()->setCellValue('C'.$x, $rows2['nama_penyelenggara']);
				$this->excel->getActiveSheet()->setCellValue('D'.$x, $rows2['alamat']);
				$this->excel->getActiveSheet()->setCellValue('E'.$x, $rows2['diwakili_oleh']);
				$this->excel->getActiveSheet()->setCellValue('F'.$x, $rows2['no_telp']);
				$this->excel->getActiveSheet()->setCellValueExplicit('F'.$x, $rows2['no_telp'], PHPExcel_Cell_DataType::TYPE_STRING);

				$this->excel->getActiveSheet()->setCellValue('B4', strtoupper("Data Penyelenggara"));
				$this->excel->getActiveSheet()->setCellValue('B5', $date);	

			}
		}

		$styleArray = array(
			'borders' => array(
			    'allborders' => array(
			    'style' => PHPExcel_Style_Border::BORDER_THIN
			    )
			),
			'font'  => array(
			    'size'  => 9,
			    'name'  => 'verdana'
			)
		);

		$this->excel->getActiveSheet()->getStyle('B8:F'.$x)->applyFromArray($styleArray);
		unset($styleArray);

		$styleArray1 = array(
		    'font'  => array(
		    'bold'  => true,
		    'uppercase' => true,
		    'size'  => 11,
		    'name'  => 'Calibri'
		    )
		);

		$this->excel->getActiveSheet()->getColumnDimension('B')->setWidth(22);	
		$this->excel->getActiveSheet()->getColumnDimension('C')->setWidth(36);
		$this->excel->getActiveSheet()->getColumnDimension('D')->setWidth(75);
		$this->excel->getActiveSheet()->getColumnDimension('E')->setWidth(22);
		$this->excel->getActiveSheet()->getColumnDimension('F')->setWidth(22);

		/*	$this->excel->getActiveSheet()->getStyle('D1:E'.$this->excel->getActiveSheet()->getHighestRow())->getNumberFormat()->setFormatCode('#,##0.00'); 

			$this->excel->getActiveSheet()->getStyle('C1:C'.$this->excel->getActiveSheet()->getHighestRow())
	    	->getAlignment()->setWrapText(true);
	    	$this->excel->getActiveSheet()->getStyle('E1:E'.$this->excel->getActiveSheet()->getHighestRow())
	    	->getAlignment()->setWrapText(true);*/

			//set aligment to center for that merged cell (A1 to D1)
			// $this->excel->getActiveSheet()->getStyle('B1:B2')->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
			$this->excel->getActiveSheet()->getStyle('B4:B5')->getFont()->setBold(true);

			$filename= 'Laporan Data Penyelenggara_'.$date.'.xls'; //save our workbook as this file name
			header('Content-Type: application/vnd.ms-excel'); //mime type
			header('Content-Disposition: attachment;filename="'.$filename.'"'); //tell browser what's the file name
			header('Cache-Control: max-age=0'); //no cache
			header('Content-Type: text/html; charset=utf-8');
				             
			//save it to Excel5 format (excel 2003 .XLS file), change this to 'Excel2007' (and adjust the filename extension, also the header mime type)
			//if you want to save it as .XLSX Excel 2007 format
			$objWriter = PHPExcel_IOFactory::createWriter($this->excel, 'Excel5');  
			//force user to download the Excel file without writing it to server's HD
			$objWriter->save('php://output');
	}

	function surat_penyelenggara_all(){

		$status_tenant='Tenant';
		$tanggal=get('tanggal');
		$x=0;

		$ls_sql	= " SELECT	*
					FROM	pro_surat_penyelenggara
					WHERE	(UPPER(no_surat) LIKE '%".strtoupper(post('keyword'))."%'
							OR UPPER(nama_kegiatan) LIKE '%".strtoupper(post('keyword'))."%')
					ORDER BY ".(post('sort')=='' ? 'no_surat' : post('sort'))." ".(post('order')=='' ? 'asc' : post('order'));	
		
		$ls_sql2	= "	SELECT COUNT(1)
						FROM	pro_surat_penyelenggara
					   	WHERE	(UPPER(no_surat) LIKE '%".strtoupper(post('keyword'))."%'
							OR UPPER(nama_kegiatan) LIKE '%".strtoupper(post('keyword'))."%')
							ORDER BY ".(post('sort')=='' ? 'no_surat' : post('sort'))." ".(post('order')=='' ? 'asc' : post('order'));
		
		$total = $this->get_data($ls_sql2);

		$result = $this->db->query($ls_sql);

		$data_p = array(	'rows'=> $result->result_array(), 
								'total' => $total);

		$date = date('Y-m-d');

		//load our new PHPExcel library
		$this->load->library('excel');
		//activate worksheet number 1
		$this->excel->setActiveSheetIndex(0);
		//name the worksheet
		$this->excel->getActiveSheet()->setTitle("Data Surat Penyelenggara");

		

			
		if ($data_p) {

			$styleArrayBorder = array(
				'borders' => array(
					'allborders' => array(
					'style' => PHPExcel_Style_Border::BORDER_THIN
					)
				)
			);

			$this->excel->getActiveSheet()->setCellValue('B8', 'No Surat');
			$this->excel->getActiveSheet()->setCellValue('C8', 'Nama Penyelenggara');
			$this->excel->getActiveSheet()->setCellValue('D8', 'Alamat');
			$this->excel->getActiveSheet()->setCellValue('E8', 'Diwakili Oleh');
			$this->excel->getActiveSheet()->setCellValue('F8', 'No Telephone');
			$this->excel->getActiveSheet()->setCellValue('G8', 'Nama Kegiatan');
			$this->excel->getActiveSheet()->setCellValue('H8', 'Tanggal Mulai Kegiatan');
			$this->excel->getActiveSheet()->setCellValue('I8', 'Tanggal Akhir Kegiatan');
			$this->excel->getActiveSheet()->setCellValue('J8', 'Pukul');
			$this->excel->getActiveSheet()->setCellValue('K8', 'Tempat Kegiatan');
			$this->excel->getActiveSheet()->setCellValue('L8', 'Catatan Kegiatan');
			
			
			$this->excel->getActiveSheet()->getStyle('B8:L8')->getFont()->setBold(true);
			$this->excel->getActiveSheet()->getStyle('B8:L8')->getFill()->applyFromArray(array('type' => PHPExcel_Style_Fill::FILL_SOLID,'startcolor' => array('rgb' => 'B2B2B2')));
			$this->excel->getActiveSheet()->getStyle('B8:L8')->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_CENTER);

			$x = 8;

			for($i=0;$i<=$data_p['total']-1;$i++){
				$x++;

				$rows = $data_p['rows'];
				$rows2 = $rows[$i];

				$this->excel->getActiveSheet()->setCellValue('B'.$x, $rows2['no_surat']);
				$this->excel->getActiveSheet()->setCellValue('C'.$x, $rows2['nama_penyelenggara']);
				$this->excel->getActiveSheet()->getStyle('C'.$x)->getAlignment()->setWrapText(true);
				$this->excel->getActiveSheet()->setCellValue('D'.$x, $rows2['alamat']);
				$this->excel->getActiveSheet()->getStyle('D'.$x)->getAlignment()->setWrapText(true);
				$this->excel->getActiveSheet()->setCellValue('E'.$x, $rows2['diwakili_oleh']);
				$this->excel->getActiveSheet()->getStyle('E'.$x)->getAlignment()->setWrapText(true);
				$this->excel->getActiveSheet()->setCellValue('F'.$x, $rows2['no_telp']);
				$this->excel->getActiveSheet()->setCellValueExplicit('F'.$x, $rows2['no_telp'], PHPExcel_Cell_DataType::TYPE_STRING);
				$this->excel->getActiveSheet()->setCellValue('G'.$x, $rows2['nama_kegiatan']);
				$this->excel->getActiveSheet()->getStyle('G'.$x)->getAlignment()->setWrapText(true);
				$this->excel->getActiveSheet()->setCellValue('H'.$x, $rows2['tanggal_mulai_kegiatan']);
				$this->excel->getActiveSheet()->setCellValue('I'.$x, $rows2['tanggal_selesai_kegiatan']);
				$this->excel->getActiveSheet()->setCellValue('J'.$x, $rows2['pukul']);
				$this->excel->getActiveSheet()->setCellValue('K'.$x, $rows2['tempat_kegiatan']);
				$this->excel->getActiveSheet()->getStyle('K'.$x)->getAlignment()->setWrapText(true);
				$this->excel->getActiveSheet()->setCellValue('L'.$x, $rows2['catatan_kegiatan']);
				$this->excel->getActiveSheet()->getStyle('L'.$x)->getAlignment()->setWrapText(true);

				$this->excel->getActiveSheet()->setCellValue('B4', strtoupper("Data Surat Izin Penyelenggara"));
				$this->excel->getActiveSheet()->setCellValue('B5', $date);	

			}
		}

		$styleArray = array(
			'borders' => array(
			    'allborders' => array(
			    'style' => PHPExcel_Style_Border::BORDER_THIN
			    )
			),
			'font'  => array(
			    'size'  => 9,
			    'name'  => 'verdana'
			)
		);

		$this->excel->getActiveSheet()->getStyle('B8:L'.$x)->applyFromArray($styleArray);
		unset($styleArray);

		$styleArray1 = array(
		    'font'  => array(
		    'bold'  => true,
		    'uppercase' => true,
		    'size'  => 11,
		    'name'  => 'Calibri'
		    )
		);

		$this->excel->getActiveSheet()->getColumnDimension('B')->setWidth(30);	
		$this->excel->getActiveSheet()->getColumnDimension('C')->setWidth(50);
		$this->excel->getActiveSheet()->getColumnDimension('D')->setWidth(50);
		$this->excel->getActiveSheet()->getColumnDimension('E')->setWidth(40);
		$this->excel->getActiveSheet()->getColumnDimension('F')->setWidth(22);
		$this->excel->getActiveSheet()->getColumnDimension('G')->setWidth(50);
		$this->excel->getActiveSheet()->getColumnDimension('H')->setWidth(25);
		$this->excel->getActiveSheet()->getColumnDimension('I')->setWidth(25);
		$this->excel->getActiveSheet()->getColumnDimension('J')->setWidth(22);
		$this->excel->getActiveSheet()->getColumnDimension('K')->setWidth(40);
		$this->excel->getActiveSheet()->getColumnDimension('L')->setWidth(50);

		/*	$this->excel->getActiveSheet()->getStyle('D1:E'.$this->excel->getActiveSheet()->getHighestRow())->getNumberFormat()->setFormatCode('#,##0.00'); 

			$this->excel->getActiveSheet()->getStyle('C1:C'.$this->excel->getActiveSheet()->getHighestRow())
	    	->getAlignment()->setWrapText(true);
	    	$this->excel->getActiveSheet()->getStyle('E1:E'.$this->excel->getActiveSheet()->getHighestRow())
	    	->getAlignment()->setWrapText(true);*/

			//set aligment to center for that merged cell (A1 to D1)
			// $this->excel->getActiveSheet()->getStyle('B1:B2')->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
			$this->excel->getActiveSheet()->getStyle('B4:B5')->getFont()->setBold(true);

			$filename= 'Laporan Surat Izin Penyelenggara'.$date.'.xls'; //save our workbook as this file name
			header('Content-Type: application/vnd.ms-excel'); //mime type
			header('Content-Disposition: attachment;filename="'.$filename.'"'); //tell browser what's the file name
			header('Cache-Control: max-age=0'); //no cache
			header('Content-Type: text/html; charset=utf-8');
				             
			//save it to Excel5 format (excel 2003 .XLS file), change this to 'Excel2007' (and adjust the filename extension, also the header mime type)
			//if you want to save it as .XLSX Excel 2007 format
			$objWriter = PHPExcel_IOFactory::createWriter($this->excel, 'Excel5');  
			//force user to download the Excel file without writing it to server's HD
			$objWriter->save('php://output');

	}

	function event_all(){

		$status_tenant='Tenant';
		$tanggal=get('tanggal');
		$x=0;

		$ls_sql	= " SELECT	
					no_event,
					no_surat,
					nama_event,
					jam_kegiatan,
					keterangan,
					jenis_event,
					izin_kepolisian,
					to_char(to_date(tanggal_mulai_kegiatan, 'dd-MON-yy'), 'DD/MM/YYYY') as tanggal_mulai_kegiatan,
					to_char(to_date(tanggal_selesai_kegiatan, 'dd-MON-yy'), 'DD/MM/YYYY') as tanggal_selesai_kegiatan
					FROM	pro_event
					WHERE	(UPPER(no_event) LIKE '%".strtoupper(post('keyword'))."%'
							OR UPPER(nama_event) LIKE '%".strtoupper(post('keyword'))."%'
							OR UPPER(tanggal_mulai_kegiatan) LIKE '%".strtoupper(post('keyword'))."%'
							OR UPPER(tanggal_selesai_kegiatan) LIKE '%".strtoupper(post('keyword'))."%'
							OR UPPER(jam_kegiatan) LIKE '%".strtoupper(post('keyword'))."%'
							OR UPPER(jenis_event) LIKE '%".strtoupper(post('keyword'))."%'
							OR UPPER(foto_info_event) LIKE '%".strtoupper(post('keyword'))."%'
							OR UPPER(keterangan) LIKE '%".strtoupper(post('keyword'))."%'
							OR UPPER(izin_kepolisian) LIKE '%".strtoupper(post('keyword'))."%'
							OR UPPER(no_surat) LIKE '%".strtoupper(post('keyword'))."%')
							ORDER BY ".(post('sort')=='' ? 'no_event' : post('sort'))." ".(post('order')=='' ? 'asc' : post('order'));	
		
		$ls_sql2	= "	SELECT COUNT(1)
						FROM	pro_event
						WHERE	(UPPER(no_event) LIKE '%".strtoupper(post('keyword'))."%'
							OR UPPER(nama_event) LIKE '%".strtoupper(post('keyword'))."%')
							ORDER BY ".(post('sort')=='' ? 'no_event' : post('sort'))." ".(post('order')=='' ? 'asc' : post('order'));
		
		$total = $this->get_data($ls_sql2);

		$result = $this->db->query($ls_sql);

		$data_p = array(	'rows'=> $result->result_array(), 
								'total' => $total);

		$date = date('Y-m-d');

		//load our new PHPExcel library
		$this->load->library('excel');
		//activate worksheet number 1
		$this->excel->setActiveSheetIndex(0);
		//name the worksheet
		$this->excel->getActiveSheet()->setTitle("Data Event");

		

			
		if ($data_p) {

			$styleArrayBorder = array(
				'borders' => array(
					'allborders' => array(
					'style' => PHPExcel_Style_Border::BORDER_THIN
					)
				)
			);

			$this->excel->getActiveSheet()->setCellValue('B8', 'No Event');
			$this->excel->getActiveSheet()->setCellValue('C8', 'No Surat');
			$this->excel->getActiveSheet()->setCellValue('D8', 'Nama Kegitan');
			$this->excel->getActiveSheet()->setCellValue('E8', 'Tanggal Mulai Kegiatan');
			$this->excel->getActiveSheet()->setCellValue('F8', 'Tanggal Selesai Kegiatan');
			$this->excel->getActiveSheet()->setCellValue('G8', 'Jam Kegiatan');
			$this->excel->getActiveSheet()->setCellValue('H8', 'Jenis Event');
			$this->excel->getActiveSheet()->setCellValue('I8', 'Izin Kepolisian');
			$this->excel->getActiveSheet()->setCellValue('J8', 'Keterangan');
			
			
			$this->excel->getActiveSheet()->getStyle('B8:J8')->getFont()->setBold(true);
			$this->excel->getActiveSheet()->getStyle('B8:J8')->getFill()->applyFromArray(array('type' => PHPExcel_Style_Fill::FILL_SOLID,'startcolor' => array('rgb' => 'B2B2B2')));
			$this->excel->getActiveSheet()->getStyle('B8:J8')->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_CENTER);

			$x = 8;

			for($i=0;$i<=$data_p['total']-1;$i++){
				$x++;

				$rows = $data_p['rows'];
				$rows2 = $rows[$i];

				$this->excel->getActiveSheet()->setCellValue('B'.$x, $rows2['no_event']);
				$this->excel->getActiveSheet()->setCellValue('C'.$x, $rows2['no_surat']);
				$this->excel->getActiveSheet()->setCellValue('D'.$x, $rows2['nama_event']);
				$this->excel->getActiveSheet()->setCellValue('E'.$x, $rows2['tanggal_mulai_kegiatan']);
				$this->excel->getActiveSheet()->setCellValue('F'.$x, $rows2['tanggal_selesai_kegiatan']);
				$this->excel->getActiveSheet()->setCellValue('G'.$x, $rows2['jam_kegiatan']);
				$this->excel->getActiveSheet()->setCellValue('H'.$x, $rows2['jenis_event']);
				$this->excel->getActiveSheet()->setCellValue('I'.$x, $rows2['izin_kepolisian']);
				$this->excel->getActiveSheet()->setCellValue('J'.$x, $rows2['keterangan']);

				$this->excel->getActiveSheet()->setCellValue('B4', strtoupper("Data Event"));
				$this->excel->getActiveSheet()->setCellValue('B5', $date);	

			}
		}

		$styleArray = array(
			'borders' => array(
			    'allborders' => array(
			    'style' => PHPExcel_Style_Border::BORDER_THIN
			    )
			),
			'font'  => array(
			    'size'  => 9,
			    'name'  => 'verdana'
			)
		);

		$this->excel->getActiveSheet()->getStyle('B8:J'.$x)->applyFromArray($styleArray);
		unset($styleArray);

		$styleArray1 = array(
		    'font'  => array(
		    'bold'  => true,
		    'uppercase' => true,
		    'size'  => 11,
		    'name'  => 'Calibri'
		    )
		);

		$this->excel->getActiveSheet()->getColumnDimension('B')->setWidth(22);	
		$this->excel->getActiveSheet()->getColumnDimension('C')->setWidth(22);
		$this->excel->getActiveSheet()->getColumnDimension('D')->setWidth(22);
		$this->excel->getActiveSheet()->getColumnDimension('E')->setWidth(22);
		$this->excel->getActiveSheet()->getColumnDimension('F')->setWidth(22);
		$this->excel->getActiveSheet()->getColumnDimension('G')->setWidth(22);
		$this->excel->getActiveSheet()->getColumnDimension('H')->setWidth(22);
		$this->excel->getActiveSheet()->getColumnDimension('I')->setWidth(22);
		$this->excel->getActiveSheet()->getColumnDimension('J')->setWidth(22);

		/*	$this->excel->getActiveSheet()->getStyle('D1:E'.$this->excel->getActiveSheet()->getHighestRow())->getNumberFormat()->setFormatCode('#,##0.00'); 

			$this->excel->getActiveSheet()->getStyle('C1:C'.$this->excel->getActiveSheet()->getHighestRow())
	    	->getAlignment()->setWrapText(true);
	    	$this->excel->getActiveSheet()->getStyle('E1:E'.$this->excel->getActiveSheet()->getHighestRow())
	    	->getAlignment()->setWrapText(true);*/

			//set aligment to center for that merged cell (A1 to D1)
			// $this->excel->getActiveSheet()->getStyle('B1:B2')->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
			$this->excel->getActiveSheet()->getStyle('B4:B5')->getFont()->setBold(true);

			$filename= 'Laporan Data Event_'.$date.'.xls'; //save our workbook as this file name
			header('Content-Type: application/vnd.ms-excel'); //mime type
			header('Content-Disposition: attachment;filename="'.$filename.'"'); //tell browser what's the file name
			header('Cache-Control: max-age=0'); //no cache
			header('Content-Type: text/html; charset=utf-8');
				             
			//save it to Excel5 format (excel 2003 .XLS file), change this to 'Excel2007' (and adjust the filename extension, also the header mime type)
			//if you want to save it as .XLSX Excel 2007 format
			$objWriter = PHPExcel_IOFactory::createWriter($this->excel, 'Excel5');  
			//force user to download the Excel file without writing it to server's HD
			$objWriter->save('php://output');

	}

	function desain_promo_all(){

		$status_tenant='Tenant';
		$tanggal=get('tanggal');
		$x=0;

		$ls_sql	= "SELECT	pro_desain_promo.*,
							TO_CHAR(PRO_DESAIN_PROMO.TANGGAL_PERMINTAAN, 'DD/MM/YYYY') as tgl_perm,
							replace(pro_desain_promo.JENIS_DESAIN, '++/n', '<br>') as jenis_design_val
					FROM	 pro_desain_promo
					WHERE	(UPPER(kode_promosi) LIKE '%".strtoupper(post('keyword'))."%'
							OR UPPER(tanggal_permintaan) LIKE '%".strtoupper(post('keyword'))."%'
							OR UPPER(id_departemen_pk) LIKE '%".strtoupper(post('keyword'))."%'
							OR UPPER(nama_departemen) LIKE '%".strtoupper(post('keyword'))."%'
							OR UPPER(status_permintaan) LIKE '%".strtoupper(post('keyword'))."%'
							OR UPPER(nama_desain) LIKE '%".strtoupper(post('keyword'))."%'
							OR UPPER(jenis_desain) LIKE '%".strtoupper(post('keyword'))."%'
							OR UPPER(upload_desain) LIKE '%".strtoupper(post('keyword'))."%'
							OR UPPER(keterangan) LIKE '%".strtoupper(post('keyword'))."%')
					ORDER BY ".(post('sort')=='' ? 'kode_promosi' : post('sort'))." ".(post('order')=='' ? 'asc' : post('order'));
		
		$ls_sql2	= "	SELECT COUNT(1)
						FROM	 pro_desain_promo
						WHERE	(UPPER(kode_promosi) LIKE '%".strtoupper(post('keyword'))."%'
							OR UPPER(jenis_desain) LIKE '%".strtoupper(post('keyword'))."%'
							OR UPPER(upload_desain) LIKE '%".strtoupper(post('keyword'))."%'
							OR UPPER(keterangan) LIKE '%".strtoupper(post('keyword'))."%')
							ORDER BY ".(post('sort')=='' ? 'kode_promosi' : post('sort'))." ".(post('order')=='' ? 'asc' : post('order'));
		
		$total = $this->get_data($ls_sql2);

		$result = $this->db->query($ls_sql);

		$data_p = array(	'rows'=> $result->result_array(), 
								'total' => $total);

		$date = date('Y-m-d');

		//load our new PHPExcel library
		$this->load->library('excel');
		//activate worksheet number 1
		$this->excel->setActiveSheetIndex(0);
		//name the worksheet
		$this->excel->getActiveSheet()->setTitle("Data Desain Promo");

		

			
		if ($data_p) {

			$styleArrayBorder = array(
				'borders' => array(
					'allborders' => array(
					'style' => PHPExcel_Style_Border::BORDER_THIN
					)
				)
			);

			$this->excel->getActiveSheet()->setCellValue('B8', 'Kode Promo');
			$this->excel->getActiveSheet()->setCellValue('C8', 'Tanggal Permintaan');
			$this->excel->getActiveSheet()->setCellValue('D8', 'ID Departement');
			$this->excel->getActiveSheet()->setCellValue('E8', 'Nama Departement');
			$this->excel->getActiveSheet()->setCellValue('F8', 'Status Permintaan');
			$this->excel->getActiveSheet()->setCellValue('G8', 'Nama Desain');
			$this->excel->getActiveSheet()->setCellValue('H8', 'Jenis Desain');
			$this->excel->getActiveSheet()->setCellValue('I8', 'Keterangan');
			
			
			$this->excel->getActiveSheet()->getStyle('B8:I8')->getFont()->setBold(true);
			$this->excel->getActiveSheet()->getStyle('B8:I8')->getFill()->applyFromArray(array('type' => PHPExcel_Style_Fill::FILL_SOLID,'startcolor' => array('rgb' => 'B2B2B2')));
			$this->excel->getActiveSheet()->getStyle('B8:I8')->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_CENTER);

			$x = 8;

			for($i=0;$i<=$data_p['total']-1;$i++){
				$x++;

				$rows = $data_p['rows'];
				$rows2 = $rows[$i];

				$this->excel->getActiveSheet()->setCellValue('B'.$x, $rows2['kode_promosi']);
				$this->excel->getActiveSheet()->setCellValue('C'.$x, $rows2['tanggal_permintaan']);
				$this->excel->getActiveSheet()->setCellValue('D'.$x, $rows2['id_departemen_pk']);
				$this->excel->getActiveSheet()->setCellValue('E'.$x, $rows2['nama_departemen']);
				$this->excel->getActiveSheet()->setCellValue('F'.$x, $rows2['status_permintaan']);
				$this->excel->getActiveSheet()->setCellValue('G'.$x, $rows2['nama_desain']);
				$this->excel->getActiveSheet()->setCellValue('H'.$x, $rows2['jenis_desain']);
				$this->excel->getActiveSheet()->setCellValue('I'.$x, $rows2['keterangan']);

				$this->excel->getActiveSheet()->setCellValue('B4', strtoupper("Data Desain Promo"));
				$this->excel->getActiveSheet()->setCellValue('B5', $date);	

			}
		}

		$styleArray = array(
			'borders' => array(
			    'allborders' => array(
			    'style' => PHPExcel_Style_Border::BORDER_THIN
			    )
			),
			'font'  => array(
			    'size'  => 9,
			    'name'  => 'verdana'
			)
		);

		$this->excel->getActiveSheet()->getStyle('B8:I'.$x)->applyFromArray($styleArray);
		unset($styleArray);

		$styleArray1 = array(
		    'font'  => array(
		    'bold'  => true,
		    'uppercase' => true,
		    'size'  => 11,
		    'name'  => 'Calibri'
		    )
		);

		$this->excel->getActiveSheet()->getColumnDimension('B')->setWidth(22);	
		$this->excel->getActiveSheet()->getColumnDimension('C')->setWidth(22);
		$this->excel->getActiveSheet()->getColumnDimension('D')->setWidth(22);
		$this->excel->getActiveSheet()->getColumnDimension('E')->setWidth(22);
		$this->excel->getActiveSheet()->getColumnDimension('F')->setWidth(22);
		$this->excel->getActiveSheet()->getColumnDimension('G')->setWidth(22);
		$this->excel->getActiveSheet()->getColumnDimension('H')->setWidth(22);
		$this->excel->getActiveSheet()->getColumnDimension('I')->setWidth(22);
		$this->excel->getActiveSheet()->getColumnDimension('J')->setWidth(22);

		/*	$this->excel->getActiveSheet()->getStyle('D1:E'.$this->excel->getActiveSheet()->getHighestRow())->getNumberFormat()->setFormatCode('#,##0.00'); 

			$this->excel->getActiveSheet()->getStyle('C1:C'.$this->excel->getActiveSheet()->getHighestRow())
	    	->getAlignment()->setWrapText(true);
	    	$this->excel->getActiveSheet()->getStyle('E1:E'.$this->excel->getActiveSheet()->getHighestRow())
	    	->getAlignment()->setWrapText(true);*/

			//set aligment to center for that merged cell (A1 to D1)
			// $this->excel->getActiveSheet()->getStyle('B1:B2')->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
			$this->excel->getActiveSheet()->getStyle('B4:B5')->getFont()->setBold(true);

			$filename= 'Laporan Desain Promo_'.$date.'.xls'; //save our workbook as this file name
			header('Content-Type: application/vnd.ms-excel'); //mime type
			header('Content-Disposition: attachment;filename="'.$filename.'"'); //tell browser what's the file name
			header('Cache-Control: max-age=0'); //no cache
			header('Content-Type: text/html; charset=utf-8');
				             
			//save it to Excel5 format (excel 2003 .XLS file), change this to 'Excel2007' (and adjust the filename extension, also the header mime type)
			//if you want to save it as .XLSX Excel 2007 format
			$objWriter = PHPExcel_IOFactory::createWriter($this->excel, 'Excel5');  
			//force user to download the Excel file without writing it to server's HD
			$objWriter->save('php://output');

	}

	function data_mitra_all(){

		$status_tenant='Tenant';
		$tanggal=get('tanggal');
		$x=0;

		$ls_sql	= "	SELECT	*
					FROM	pro_mitra
					WHERE	UPPER(status_mitra) = 'BELUM AKTIF' AND
							(UPPER(kode_mitra) LIKE '%".strtoupper(post('keyword'))."%'
							OR UPPER(ktp) LIKE '%".strtoupper(post('keyword'))."%'
							OR UPPER(situ) LIKE '%".strtoupper(post('keyword'))."%'
							OR UPPER(siup) LIKE '%".strtoupper(post('keyword'))."%'
							OR UPPER(npwp) LIKE '%".strtoupper(post('keyword'))."%'
							OR UPPER(nama_pemilik) LIKE '%".strtoupper(post('keyword'))."%'
							OR UPPER(alamat_lengkap) LIKE '%".strtoupper(post('keyword'))."%'
							OR UPPER(no_telp) LIKE '%".strtoupper(post('keyword'))."%'
							OR UPPER(no_hand) LIKE '%".strtoupper(post('keyword'))."%'
							OR UPPER(status_mitra) LIKE '%".strtoupper(post('keyword'))."%')
							ORDER BY ".(post('sort')=='' ? 'kode_mitra' : post('sort'))." ".(post('order')=='' ? 'asc' : post('order'));

		$ls_sql2	= "	SELECT COUNT(1)
						FROM	pro_mitra
						WHERE	UPPER(status_mitra) = 'BELUM AKTIF' AND
							(UPPER(kode_mitra) LIKE '%".strtoupper(post('keyword'))."%'
							OR UPPER(ktp) LIKE '%".strtoupper(post('keyword'))."%'
							OR UPPER(situ) LIKE '%".strtoupper(post('keyword'))."%'
							OR UPPER(siup) LIKE '%".strtoupper(post('keyword'))."%'
							OR UPPER(npwp) LIKE '%".strtoupper(post('keyword'))."%'
							OR UPPER(nama_pemilik) LIKE '%".strtoupper(post('keyword'))."%'
							OR UPPER(alamat_lengkap) LIKE '%".strtoupper(post('keyword'))."%'
							OR UPPER(no_telp) LIKE '%".strtoupper(post('keyword'))."%'
							OR UPPER(no_hand) LIKE '%".strtoupper(post('keyword'))."%'
							OR UPPER(status_mitra) LIKE '%".strtoupper(post('keyword'))."%')
							ORDER BY ".(post('sort')=='' ? 'kode_mitra' : post('sort'))." ".(post('order')=='' ? 'asc' : post('order'));
		
		$total = $this->get_data($ls_sql2);

		$result = $this->db->query($ls_sql);

		$data_p = array(	'rows'=> $result->result_array(), 
								'total' => $total);

		$date = date('Y-m-d');

		//load our new PHPExcel library
		$this->load->library('excel');
		//activate worksheet number 1
		$this->excel->setActiveSheetIndex(0);
		//name the worksheet
		$this->excel->getActiveSheet()->setTitle("Data Mitra");

		

			
		if ($data_p) {

			$styleArrayBorder = array(
				'borders' => array(
					'allborders' => array(
					'style' => PHPExcel_Style_Border::BORDER_THIN
					)
				)
			);

			$this->excel->getActiveSheet()->setCellValue('B8', 'Kode Mitra');
			$this->excel->getActiveSheet()->setCellValue('C8', 'KTP');
			$this->excel->getActiveSheet()->setCellValue('D8', 'SITU');
			$this->excel->getActiveSheet()->setCellValue('E8', 'SIUP');
			$this->excel->getActiveSheet()->setCellValue('F8', 'NPWP');
			$this->excel->getActiveSheet()->setCellValue('G8', 'Nama Pemilik');
			$this->excel->getActiveSheet()->setCellValue('H8', 'Alamat Lengkap');
			$this->excel->getActiveSheet()->setCellValue('I8', 'No Telephone');
			$this->excel->getActiveSheet()->setCellValue('J8', 'No Handphone');
			$this->excel->getActiveSheet()->setCellValue('K8', 'Status Mitra');

			
			
			$this->excel->getActiveSheet()->getStyle('B8:K8')->getFont()->setBold(true);
			$this->excel->getActiveSheet()->getStyle('B8:K8')->getFill()->applyFromArray(array('type' => PHPExcel_Style_Fill::FILL_SOLID,'startcolor' => array('rgb' => 'B2B2B2')));
			$this->excel->getActiveSheet()->getStyle('B8:K8')->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_CENTER);

			$x = 8;

			for($i=0;$i<=$data_p['total']-1;$i++){
				$x++;

				$rows = $data_p['rows'];
				$rows2 = $rows[$i];

				$this->excel->getActiveSheet()->setCellValue('B'.$x, $rows2['kode_mitra']);
				$this->excel->getActiveSheet()->setCellValueExplicit('C'.$x, $rows2['ktp'], PHPExcel_Cell_DataType::TYPE_STRING);
				$this->excel->getActiveSheet()->setCellValueExplicit('D'.$x, $rows2['situ'], PHPExcel_Cell_DataType::TYPE_STRING);
				$this->excel->getActiveSheet()->setCellValueExplicit('E'.$x, $rows2['siup'], PHPExcel_Cell_DataType::TYPE_STRING);
				$this->excel->getActiveSheet()->setCellValueExplicit('F'.$x, $rows2['npwp'], PHPExcel_Cell_DataType::TYPE_STRING);
				$this->excel->getActiveSheet()->setCellValue('F'.$x, $rows2['npwp']);
				$this->excel->getActiveSheet()->setCellValue('G'.$x, $rows2['nama_mitra']);
				$this->excel->getActiveSheet()->setCellValue('H'.$x, $rows2['alamat_lengkap']);
				$this->excel->getActiveSheet()->setCellValueExplicit('I'.$x, $rows2['no_telp'], PHPExcel_Cell_DataType::TYPE_STRING);
				$this->excel->getActiveSheet()->setCellValueExplicit('J'.$x, $rows2['no_hand'], PHPExcel_Cell_DataType::TYPE_STRING);
				$this->excel->getActiveSheet()->setCellValue('K'.$x, $rows2['status_mitra']);

				$this->excel->getActiveSheet()->setCellValue('B4', strtoupper("Data Mitra"));
				$this->excel->getActiveSheet()->setCellValue('B5', $date);	

			}
		}

		$styleArray = array(
			'borders' => array(
			    'allborders' => array(
			    'style' => PHPExcel_Style_Border::BORDER_THIN
			    )
			),
			'font'  => array(
			    'size'  => 9,
			    'name'  => 'verdana'
			)
		);

		$this->excel->getActiveSheet()->getStyle('B8:K'.$x)->applyFromArray($styleArray);
		unset($styleArray);

		$styleArray1 = array(
		    'font'  => array(
		    'bold'  => true,
		    'uppercase' => true,
		    'size'  => 11,
		    'name'  => 'Calibri'
		    )
		);

		$this->excel->getActiveSheet()->getColumnDimension('B')->setWidth(22);	
		$this->excel->getActiveSheet()->getColumnDimension('C')->setWidth(26);
		$this->excel->getActiveSheet()->getColumnDimension('D')->setWidth(26);
		$this->excel->getActiveSheet()->getColumnDimension('E')->setWidth(26);
		$this->excel->getActiveSheet()->getColumnDimension('F')->setWidth(26);
		$this->excel->getActiveSheet()->getColumnDimension('G')->setWidth(35);
		$this->excel->getActiveSheet()->getColumnDimension('H')->setWidth(60);
		$this->excel->getActiveSheet()->getColumnDimension('I')->setWidth(26);
		$this->excel->getActiveSheet()->getColumnDimension('J')->setWidth(26);
		$this->excel->getActiveSheet()->getColumnDimension('K')->setWidth(22);

		/*	$this->excel->getActiveSheet()->getStyle('D1:E'.$this->excel->getActiveSheet()->getHighestRow())->getNumberFormat()->setFormatCode('#,##0.00'); 

			$this->excel->getActiveSheet()->getStyle('C1:C'.$this->excel->getActiveSheet()->getHighestRow())
	    	->getAlignment()->setWrapText(true);
	    	$this->excel->getActiveSheet()->getStyle('E1:E'.$this->excel->getActiveSheet()->getHighestRow())
	    	->getAlignment()->setWrapText(true);*/

			//set aligment to center for that merged cell (A1 to D1)
			// $this->excel->getActiveSheet()->getStyle('B1:B2')->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
			$this->excel->getActiveSheet()->getStyle('B4:B5')->getFont()->setBold(true);

			$filename= 'Laporan Data Mitra_'.$date.'.xls'; //save our workbook as this file name
			header('Content-Type: application/vnd.ms-excel'); //mime type
			header('Content-Disposition: attachment;filename="'.$filename.'"'); //tell browser what's the file name
			header('Cache-Control: max-age=0'); //no cache
			header('Content-Type: text/html; charset=utf-8');
				             
			//save it to Excel5 format (excel 2003 .XLS file), change this to 'Excel2007' (and adjust the filename extension, also the header mime type)
			//if you want to save it as .XLSX Excel 2007 format
			$objWriter = PHPExcel_IOFactory::createWriter($this->excel, 'Excel5');  
			//force user to download the Excel file without writing it to server's HD
			$objWriter->save('php://output');

	}

	function data_mitra_aktif_all(){

		$status_tenant='Tenant';
		$tanggal=get('tanggal');
		$x=0;

		$ls_sql	= "	SELECT	kode_mitra,
							ktp,
							situ,
							siup,
							npwp,
							nama_pemilik,
							nama_toko_mitra,
							alamat_lengkap,
							no_telp,
							no_hand,
							status_mitra,
							no_kontrak,
							TO_CHAR(awal_kerja,'DD/MM/YYYY') as awal_kerja,
							TO_CHAR(akhir_kerja,'DD/MM/YYYY') as akhir_kerja,
							fee_mitra,
							no_rekening,
							nama_bank,
							atas_nama,
							keterangan
					FROM	pro_mitra
					WHERE	UPPER(status_mitra) = 'MITRA AKTIF' AND
							(UPPER(kode_mitra) LIKE '%".strtoupper(post('keyword'))."%'
							OR UPPER(ktp) LIKE '%".strtoupper(post('keyword'))."%'
							OR UPPER(nama_toko_mitra) LIKE '%".strtoupper(post('keyword'))."%'
							OR UPPER(nama_pemilik) LIKE '%".strtoupper(post('keyword'))."%'
							OR UPPER(alamat_lengkap) LIKE '%".strtoupper(post('keyword'))."%'
							OR UPPER(no_telp) LIKE '%".strtoupper(post('keyword'))."%'
							OR UPPER(no_hand) LIKE '%".strtoupper(post('keyword'))."%'
							OR UPPER(status_mitra) LIKE '%".strtoupper(post('keyword'))."%'
							OR UPPER(no_kontrak) LIKE '%".strtoupper(post('keyword'))."%'
							OR UPPER(awal_kerja) LIKE '%".strtoupper(post('keyword'))."%'
							OR UPPER(akhir_kerja) LIKE '%".strtoupper(post('keyword'))."%'
							OR UPPER(fee_mitra) LIKE '%".strtoupper(post('keyword'))."%'
							OR UPPER(no_rekening) LIKE '%".strtoupper(post('keyword'))."%'
							OR UPPER(nama_bank) LIKE '%".strtoupper(post('keyword'))."%'
							OR UPPER(atas_nama) LIKE '%".strtoupper(post('keyword'))."%')
							ORDER BY ".(post('sort')=='' ? 'kode_mitra' : post('sort'))." ".(post('order')=='' ? 'asc' : post('order'));

		$ls_sql2	= "	SELECT COUNT(1)
						FROM	pro_mitra
						WHERE	UPPER(status_mitra) = 'MITRA AKTIF' AND
							(UPPER(kode_mitra) LIKE '%".strtoupper(post('keyword'))."%'
							OR UPPER(ktp) LIKE '%".strtoupper(post('keyword'))."%'
							OR UPPER(nama_toko_mitra) LIKE '%".strtoupper(post('keyword'))."%'
							OR UPPER(nama_pemilik) LIKE '%".strtoupper(post('keyword'))."%'
							OR UPPER(alamat_lengkap) LIKE '%".strtoupper(post('keyword'))."%'
							OR UPPER(no_telp) LIKE '%".strtoupper(post('keyword'))."%'
							OR UPPER(no_hand) LIKE '%".strtoupper(post('keyword'))."%'
							OR UPPER(status_mitra) LIKE '%".strtoupper(post('keyword'))."%'
							OR UPPER(no_kontrak) LIKE '%".strtoupper(post('keyword'))."%'
							OR UPPER(awal_kerja) LIKE '%".strtoupper(post('keyword'))."%'
							OR UPPER(akhir_kerja) LIKE '%".strtoupper(post('keyword'))."%'
							OR UPPER(fee_mitra) LIKE '%".strtoupper(post('keyword'))."%'
							OR UPPER(no_rekening) LIKE '%".strtoupper(post('keyword'))."%'
							OR UPPER(nama_bank) LIKE '%".strtoupper(post('keyword'))."%'
							OR UPPER(atas_nama) LIKE '%".strtoupper(post('keyword'))."%')
							ORDER BY ".(post('sort')=='' ? 'kode_mitra' : post('sort'))." ".(post('order')=='' ? 'asc' : post('order'));
		
		$total = $this->get_data($ls_sql2);

		$result = $this->db->query($ls_sql);

		$data_p = array(	'rows'=> $result->result_array(), 
								'total' => $total);

		$date = date('Y-m-d');

		//load our new PHPExcel library
		$this->load->library('excel');
		//activate worksheet number 1
		$this->excel->setActiveSheetIndex(0);
		//name the worksheet
		$this->excel->getActiveSheet()->setTitle("Data Mitra Aktif");

		

			
		if ($data_p) {

			$styleArrayBorder = array(
				'borders' => array(
					'allborders' => array(
					'style' => PHPExcel_Style_Border::BORDER_THIN
					)
				)
			);

			$this->excel->getActiveSheet()->setCellValue('B8', 'Kode Mitra');
			$this->excel->getActiveSheet()->setCellValue('C8', 'KTP');
			$this->excel->getActiveSheet()->setCellValue('D8', 'SITU');
			$this->excel->getActiveSheet()->setCellValue('E8', 'SIUP');
			$this->excel->getActiveSheet()->setCellValue('F8', 'NPWP');
			$this->excel->getActiveSheet()->setCellValue('G8', 'Nama Pemilik');
			$this->excel->getActiveSheet()->setCellValue('H8', 'Alamat Lengkap');
			$this->excel->getActiveSheet()->setCellValue('I8', 'No Telephone');
			$this->excel->getActiveSheet()->setCellValue('J8', 'No Handphone');
			$this->excel->getActiveSheet()->setCellValue('K8', 'Status Mitra');
			$this->excel->getActiveSheet()->setCellValue('L8', 'No Kontrak');
			$this->excel->getActiveSheet()->setCellValue('M8', 'Awal Kerja');
			$this->excel->getActiveSheet()->setCellValue('N8', 'Akhir Mitra');
			$this->excel->getActiveSheet()->setCellValue('O8', 'Fee Mitra');
			$this->excel->getActiveSheet()->setCellValue('P8', 'No Rekening');
			$this->excel->getActiveSheet()->setCellValue('Q8', 'Nama Bank');
			$this->excel->getActiveSheet()->setCellValue('R8', 'Atas Nama');
			$this->excel->getActiveSheet()->setCellValue('S8', 'Keterangan');
			
			
			$this->excel->getActiveSheet()->getStyle('B8:S8')->getFont()->setBold(true);
			$this->excel->getActiveSheet()->getStyle('B8:S8')->getFill()->applyFromArray(array('type' => PHPExcel_Style_Fill::FILL_SOLID,'startcolor' => array('rgb' => 'B2B2B2')));
			$this->excel->getActiveSheet()->getStyle('B8:S8')->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_CENTER);

			$x = 8;

			for($i=0;$i<=$data_p['total']-1;$i++){
				$x++;

				$rows = $data_p['rows'];
				$rows2 = $rows[$i];

				$this->excel->getActiveSheet()->setCellValue('B'.$x, $rows2['kode_mitra']);
				$this->excel->getActiveSheet()->setCellValueExplicit('C'.$x, $rows2['ktp'], PHPExcel_Cell_DataType::TYPE_STRING);
				$this->excel->getActiveSheet()->setCellValueExplicit('D'.$x, $rows2['situ'], PHPExcel_Cell_DataType::TYPE_STRING);
				$this->excel->getActiveSheet()->setCellValueExplicit('E'.$x, $rows2['siup'], PHPExcel_Cell_DataType::TYPE_STRING);
				$this->excel->getActiveSheet()->setCellValueExplicit('F'.$x, $rows2['npwp'], PHPExcel_Cell_DataType::TYPE_STRING);
				$this->excel->getActiveSheet()->setCellValue('G'.$x, $rows2['nama_pemilik']);
				$this->excel->getActiveSheet()->setCellValue('H'.$x, $rows2['alamat_lengkap']);
				$this->excel->getActiveSheet()->setCellValueExplicit('I'.$x, $rows2['no_telp'], PHPExcel_Cell_DataType::TYPE_STRING);
				$this->excel->getActiveSheet()->setCellValueExplicit('J'.$x, $rows2['no_hand'], PHPExcel_Cell_DataType::TYPE_STRING);
				$this->excel->getActiveSheet()->setCellValue('K'.$x, $rows2['status_mitra']);
				$this->excel->getActiveSheet()->setCellValue('L'.$x, $rows2['no_kontrak']);
				$this->excel->getActiveSheet()->setCellValue('M'.$x, $rows2['awal_kerja']);
				$this->excel->getActiveSheet()->setCellValue('N'.$x, $rows2['akhir_kerja']);
				$this->excel->getActiveSheet()->setCellValue('O'.$x, $rows2['fee_mitra']);
				//$this->excel->getActiveSheet()->getStyle('O'.$x)->getNumberFormat()->setFormatCode('Rp #,##0'); 
				$this->excel->getActiveSheet()->setCellValueExplicit('P'.$x, $rows2['no_rekening'], PHPExcel_Cell_DataType::TYPE_STRING);
				$this->excel->getActiveSheet()->setCellValue('Q'.$x, $rows2['nama_bank']);
				$this->excel->getActiveSheet()->setCellValue('R'.$x, $rows2['atas_nama']);
				$this->excel->getActiveSheet()->setCellValue('S'.$x, $rows2['keterangan']);
				$this->excel->getActiveSheet()->getStyle('S'.$x)->getAlignment()->setWrapText(true);

				$this->excel->getActiveSheet()->setCellValue('B4', strtoupper("Data Mitra Aktif"));
				$this->excel->getActiveSheet()->setCellValue('B5', $date);	

			}
		}

		$styleArray = array(
			'borders' => array(
			    'allborders' => array(
			    'style' => PHPExcel_Style_Border::BORDER_THIN
			    )
			),
			'font'  => array(
			    'size'  => 9,
			    'name'  => 'verdana'
			)
		);

		$this->excel->getActiveSheet()->getStyle('B8:S'.$x)->applyFromArray($styleArray);
		unset($styleArray);

		$styleArray1 = array(
		    'font'  => array(
		    'bold'  => true,
		    'uppercase' => true,
		    'size'  => 11,
		    'name'  => 'Calibri'
		    )
		);

		$this->excel->getActiveSheet()->getColumnDimension('B')->setWidth(22);	
		$this->excel->getActiveSheet()->getColumnDimension('C')->setWidth(26);
		$this->excel->getActiveSheet()->getColumnDimension('D')->setWidth(26);
		$this->excel->getActiveSheet()->getColumnDimension('E')->setWidth(26);
		$this->excel->getActiveSheet()->getColumnDimension('F')->setWidth(26);
		$this->excel->getActiveSheet()->getColumnDimension('G')->setWidth(35);
		$this->excel->getActiveSheet()->getColumnDimension('H')->setWidth(60);
		$this->excel->getActiveSheet()->getColumnDimension('I')->setWidth(26);
		$this->excel->getActiveSheet()->getColumnDimension('J')->setWidth(26);
		$this->excel->getActiveSheet()->getColumnDimension('K')->setWidth(22);
		$this->excel->getActiveSheet()->getColumnDimension('L')->setWidth(37);
		$this->excel->getActiveSheet()->getColumnDimension('M')->setWidth(22);
		$this->excel->getActiveSheet()->getColumnDimension('N')->setWidth(22);
		$this->excel->getActiveSheet()->getColumnDimension('O')->setWidth(22);
		$this->excel->getActiveSheet()->getColumnDimension('P')->setWidth(30);
		$this->excel->getActiveSheet()->getColumnDimension('Q')->setWidth(26);
		$this->excel->getActiveSheet()->getColumnDimension('R')->setWidth(26);
		$this->excel->getActiveSheet()->getColumnDimension('S')->setWidth(50);

		/*	$this->excel->getActiveSheet()->getStyle('D1:E'.$this->excel->getActiveSheet()->getHighestRow())->getNumberFormat()->setFormatCode('#,##0.00'); 

			$this->excel->getActiveSheet()->getStyle('C1:C'.$this->excel->getActiveSheet()->getHighestRow())
	    	->getAlignment()->setWrapText(true);
	    	$this->excel->getActiveSheet()->getStyle('E1:E'.$this->excel->getActiveSheet()->getHighestRow())
	    	->getAlignment()->setWrapText(true);*/

			//set aligment to center for that merged cell (A1 to D1)
			// $this->excel->getActiveSheet()->getStyle('B1:B2')->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
			$this->excel->getActiveSheet()->getStyle('B4:B5')->getFont()->setBold(true);

			$filename= 'Laporan Data Mitra_'.$date.'.xls'; //save our workbook as this file name
			header('Content-Type: application/vnd.ms-excel'); //mime type
			header('Content-Disposition: attachment;filename="'.$filename.'"'); //tell browser what's the file name
			header('Cache-Control: max-age=0'); //no cache
			header('Content-Type: text/html; charset=utf-8');
				             
			//save it to Excel5 format (excel 2003 .XLS file), change this to 'Excel2007' (and adjust the filename extension, also the header mime type)
			//if you want to save it as .XLSX Excel 2007 format
			$objWriter = PHPExcel_IOFactory::createWriter($this->excel, 'Excel5');  
			//force user to download the Excel file without writing it to server's HD
			$objWriter->save('php://output');

	}


	function laporan_perangkat_baru()
	{
		
		$x=0;

		$ls_sql	= " SELECT	*
					FROM	pro_barang
					WHERE	kondisi ='Baru' AND (UPPER(kode_barang) LIKE '%".strtoupper(post('keyword'))."%'
							OR UPPER(nama_barang) LIKE '%".strtoupper(post('keyword'))."%') 
							ORDER BY ".(post('sort')=='' ? 'kode_barang' : post('sort'))." ".(post('order')=='' ? 'asc' : post('order'));	
	
		$ls_sql2	= "	SELECT COUNT(1)
					FROM	pro_barang
					WHERE	kondisi ='Baru' AND (UPPER(kode_barang) LIKE '%".strtoupper(post('keyword'))."%'
							OR UPPER(nama_barang) LIKE '%".strtoupper(post('keyword'))."%') 
							ORDER BY ".(post('sort')=='' ? 'kode_barang' : post('sort'))." ".(post('order')=='' ? 'asc' : post('order'));
		
		$total = $this->get_data($ls_sql2);

		$result = $this->db->query($ls_sql);

		$data_p = array(	'rows'=> $result->result_array(), 
								'total' => $total);

		$date = date('Y-m-d');

		//load our new PHPExcel library
		$this->load->library('excel');
		//activate worksheet number 1
		$this->excel->setActiveSheetIndex(0);
		//name the worksheet
		$this->excel->getActiveSheet()->setTitle("Penggunaan Perangkat Baru");

		$no = 1;

			
		if ($data_p) {

			$styleArrayBorder = array(
				'borders' => array(
					'allborders' => array(
					'style' => PHPExcel_Style_Border::BORDER_THIN
					)
				)
			);

			$this->excel->getActiveSheet()->setCellValue('B8', 'NO');
			$this->excel->getActiveSheet()->setCellValue('C8', 'KODE PERANGKAT');
			$this->excel->getActiveSheet()->setCellValue('D8', 'KODE BARANG');
			$this->excel->getActiveSheet()->setCellValue('E8', 'NAMA BARANG');
			$this->excel->getActiveSheet()->setCellValue('F8', 'NAMA MERK');
			$this->excel->getActiveSheet()->setCellValue('G8', 'SPESIFIKASI');
			$this->excel->getActiveSheet()->setCellValue('H8', 'KONDISI BARANG');
			$this->excel->getActiveSheet()->setCellValue('I8', 'TIPE');
			$this->excel->getActiveSheet()->setCellValue('J8', 'HARGA');
			$this->excel->getActiveSheet()->setCellValue('K8', 'JUMLAH');
			$this->excel->getActiveSheet()->setCellValue('L8', 'KETERANGAN');

			$this->excel->getActiveSheet()->getStyle('B8:L8')->getFont()->setBold(true);
			$this->excel->getActiveSheet()->getStyle('B8:L8')->getFill()->applyFromArray(array('type' => PHPExcel_Style_Fill::FILL_SOLID,'startcolor' => array('rgb' => 'EEEE11')));
			$this->excel->getActiveSheet()->getStyle('B8:L8')->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_CENTER);

			$x = 8;

			for($i=0;$i<=$data_p['total']-1;$i++){
				$x++;

				$rows = $data_p['rows'];
				$rows2 = $rows[$i];

				$this->excel->getActiveSheet()->setCellValue('B'.$x, $no);
				$this->excel->getActiveSheet()->getStyle('B'.$x)->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
				$this->excel->getActiveSheet()->setCellValue('C'.$x, $rows2['kode_perangkat']);
				$this->excel->getActiveSheet()->setCellValue('D'.$x, $rows2['kode_barang']);
				$this->excel->getActiveSheet()->setCellValue('E'.$x, $rows2['nama_barang']);
				$this->excel->getActiveSheet()->setCellValue('F'.$x, $rows2['nama_merek']);
				$this->excel->getActiveSheet()->setCellValue('G'.$x, $rows2['spesifikasi']);
				$this->excel->getActiveSheet()->setCellValue('H'.$x, $rows2['kondisi']);
				$this->excel->getActiveSheet()->setCellValue('I'.$x, $rows2['tipe']);
				$this->excel->getActiveSheet()->setCellValue('J'.$x, $rows2['harga']);
				$this->excel->getActiveSheet()->getStyle('J'.$x)->getNumberFormat()->setFormatCode('Rp #,##0'); 
				$this->excel->getActiveSheet()->setCellValue('K'.$x, $rows2['jumlah']);
				$this->excel->getActiveSheet()->getStyle('K'.$x)->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
				$this->excel->getActiveSheet()->setCellValue('L'.$x, $rows2['keterangan']);

			}
		}

		$this->excel->getActiveSheet()->setCellValue('B4', strtoupper("Penggunaan Perangkat Baru"));
		$this->excel->getActiveSheet()->setCellValue('B5', '('.$date.')');			

		$styleArray = array(
			'borders' => array(
			    'allborders' => array(
			    'style' => PHPExcel_Style_Border::BORDER_THIN
			    )
			),
			'font'  => array(
			    'size'  => 9,
			    'name'  => 'verdana'
			)
		);

		$this->excel->getActiveSheet()->getStyle('B8:L'.$x)->applyFromArray($styleArray);
		unset($styleArray);

		$styleArray1 = array(
		    'font'  => array(
		    'bold'  => true,
		    'uppercase' => true,
		    'size'  => 11,
		    'name'  => 'Calibri'
		    )
		);

		$this->excel->getActiveSheet()->getColumnDimension('B')->setWidth(10);
		$this->excel->getActiveSheet()->getColumnDimension('C')->setWidth(22);
		$this->excel->getActiveSheet()->getColumnDimension('D')->setWidth(22);
		$this->excel->getActiveSheet()->getColumnDimension('E')->setWidth(35);
		$this->excel->getActiveSheet()->getColumnDimension('F')->setWidth(35);
		$this->excel->getActiveSheet()->getColumnDimension('G')->setWidth(22);
		$this->excel->getActiveSheet()->getColumnDimension('H')->setWidth(27);
		$this->excel->getActiveSheet()->getColumnDimension('I')->setWidth(22);
		$this->excel->getActiveSheet()->getColumnDimension('J')->setWidth(30);
		$this->excel->getActiveSheet()->getColumnDimension('K')->setWidth(10);
		$this->excel->getActiveSheet()->getColumnDimension('L')->setWidth(40);

		//$this->excel->getActiveSheet()->getStyle('D1:H'.$this->excel->getActiveSheet()->getHighestRow())->getNumberFormat()->setFormatCode('#,##0.00'); 

		$this->excel->getActiveSheet()->getStyle('C1:C'.$this->excel->getActiveSheet()->getHighestRow())
    	->getAlignment()->setWrapText(true);
    	$this->excel->getActiveSheet()->getStyle('K1:K'.$this->excel->getActiveSheet()->getHighestRow())
    	->getAlignment()->setWrapText(true);

		//set aligment to center for that merged cell (A1 to D1)
		// $this->excel->getActiveSheet()->getStyle('B1:B2')->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
		$this->excel->getActiveSheet()->getStyle('B4:B5')->getFont()->setBold(true);

		$filename= 'Laporan Penggunaan Perangkat Baru_'.$date.'.xls'; //save our workbook as this file name
		header('Content-Type: application/vnd.ms-excel'); //mime type
		header('Content-Disposition: attachment;filename="'.$filename.'"'); //tell browser what's the file name
		header('Cache-Control: max-age=0'); //no cache
			             
		//save it to Excel5 format (excel 2003 .XLS file), change this to 'Excel2007' (and adjust the filename extension, also the header mime type)
		//if you want to save it as .XLSX Excel 2007 format
		$objWriter = PHPExcel_IOFactory::createWriter($this->excel, 'Excel5');  
		//force user to download the Excel file without writing it to server's HD
		$objWriter->save('php://output');
	}

	function laporan_perangkat_terpakai()
	{
		
		$x=0;

		$ls_sql	= " SELECT	*
					FROM	pro_barang
					WHERE	lower(kondisi)='barang sudah terpakai' AND (UPPER(kode_barang) LIKE '%".strtoupper(post('keyword'))."%'
							OR UPPER(nama_barang) LIKE '%".strtoupper(post('keyword'))."%') 
							ORDER BY ".(post('sort')=='' ? 'kode_barang' : post('sort'))." ".(post('order')=='' ? 'asc' : post('order'));	
	
		$ls_sql2	= "	SELECT COUNT(1)
					FROM	pro_barang
					WHERE	lower(kondisi)='barang sudah terpakai' AND (UPPER(kode_barang) LIKE '%".strtoupper(post('keyword'))."%'
							OR UPPER(nama_barang) LIKE '%".strtoupper(post('keyword'))."%') 
							ORDER BY ".(post('sort')=='' ? 'kode_barang' : post('sort'))." ".(post('order')=='' ? 'asc' : post('order'));
		
		$total = $this->get_data($ls_sql2);

		$result = $this->db->query($ls_sql);

		$data_p = array(	'rows'=> $result->result_array(), 
								'total' => $total);

		$date = date('Y-m-d');

		//load our new PHPExcel library
		$this->load->library('excel');
		//activate worksheet number 1
		$this->excel->setActiveSheetIndex(0);
		//name the worksheet
		$this->excel->getActiveSheet()->setTitle("Perangkat Pernah Terpakai");

		$no = 1;

			
		if ($data_p) {

			$styleArrayBorder = array(
				'borders' => array(
					'allborders' => array(
					'style' => PHPExcel_Style_Border::BORDER_THIN
					)
				)
			);

			$this->excel->getActiveSheet()->setCellValue('B8', 'NO');
			$this->excel->getActiveSheet()->setCellValue('C8', 'KODE PERANGKAT');
			$this->excel->getActiveSheet()->setCellValue('D8', 'KODE BARANG');
			$this->excel->getActiveSheet()->setCellValue('E8', 'NAMA BARANG');
			$this->excel->getActiveSheet()->setCellValue('F8', 'NAMA MERK');
			$this->excel->getActiveSheet()->setCellValue('G8', 'SPESIFIKASI');
			$this->excel->getActiveSheet()->setCellValue('H8', 'KONDISI BARANG');
			$this->excel->getActiveSheet()->setCellValue('I8', 'TIPE');
			$this->excel->getActiveSheet()->setCellValue('J8', 'HARGA');
			$this->excel->getActiveSheet()->setCellValue('K8', 'JUMLAH');
			$this->excel->getActiveSheet()->setCellValue('L8', 'KETERANGAN');

			$this->excel->getActiveSheet()->getStyle('B8:L8')->getFont()->setBold(true);
			$this->excel->getActiveSheet()->getStyle('B8:L8')->getFill()->applyFromArray(array('type' => PHPExcel_Style_Fill::FILL_SOLID,'startcolor' => array('rgb' => 'EEEE11')));
			$this->excel->getActiveSheet()->getStyle('B8:L8')->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_CENTER);

			$x = 8;

			for($i=0;$i<=$data_p['total']-1;$i++){
				$x++;

				$rows = $data_p['rows'];
				$rows2 = $rows[$i];

				$this->excel->getActiveSheet()->setCellValue('B'.$x, $no);
				$this->excel->getActiveSheet()->getStyle('B'.$x)->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
				$this->excel->getActiveSheet()->setCellValue('C'.$x, $rows2['kode_perangkat']);
				$this->excel->getActiveSheet()->setCellValue('D'.$x, $rows2['kode_barang']);
				$this->excel->getActiveSheet()->setCellValue('E'.$x, $rows2['nama_barang']);
				$this->excel->getActiveSheet()->setCellValue('F'.$x, $rows2['nama_merek']);
				$this->excel->getActiveSheet()->setCellValue('G'.$x, $rows2['spesifikasi']);
				$this->excel->getActiveSheet()->setCellValue('H'.$x, $rows2['kondisi']);
				$this->excel->getActiveSheet()->setCellValue('I'.$x, $rows2['tipe']);
				$this->excel->getActiveSheet()->setCellValue('J'.$x, $rows2['harga']);
				$this->excel->getActiveSheet()->getStyle('J'.$x)->getNumberFormat()->setFormatCode('Rp #,##0'); 
				$this->excel->getActiveSheet()->setCellValue('K'.$x, $rows2['jumlah']);
				$this->excel->getActiveSheet()->getStyle('K'.$x)->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
				$this->excel->getActiveSheet()->setCellValue('L'.$x, $rows2['keterangan']);
			
			}
		}

		$this->excel->getActiveSheet()->setCellValue('B4', strtoupper("Perangkat Pernah Terpakai"));
		$this->excel->getActiveSheet()->setCellValue('B5', '('.$date.')');			

		$styleArray = array(
			'borders' => array(
			    'allborders' => array(
			    'style' => PHPExcel_Style_Border::BORDER_THIN
			    )
			),
			'font'  => array(
			    'size'  => 9,
			    'name'  => 'verdana'
			)
		);

		$this->excel->getActiveSheet()->getStyle('B8:L'.$x)->applyFromArray($styleArray);
		unset($styleArray);

		$styleArray1 = array(
		    'font'  => array(
		    'bold'  => true,
		    'uppercase' => true,
		    'size'  => 11,
		    'name'  => 'Calibri'
		    )
		);

		$this->excel->getActiveSheet()->getColumnDimension('B')->setWidth(10);
		$this->excel->getActiveSheet()->getColumnDimension('C')->setWidth(22);
		$this->excel->getActiveSheet()->getColumnDimension('D')->setWidth(22);
		$this->excel->getActiveSheet()->getColumnDimension('E')->setWidth(35);
		$this->excel->getActiveSheet()->getColumnDimension('F')->setWidth(35);
		$this->excel->getActiveSheet()->getColumnDimension('G')->setWidth(22);
		$this->excel->getActiveSheet()->getColumnDimension('H')->setWidth(27);
		$this->excel->getActiveSheet()->getColumnDimension('I')->setWidth(22);
		$this->excel->getActiveSheet()->getColumnDimension('J')->setWidth(30);
		$this->excel->getActiveSheet()->getColumnDimension('K')->setWidth(10);
		$this->excel->getActiveSheet()->getColumnDimension('L')->setWidth(40);

		//$this->excel->getActiveSheet()->getStyle('D1:H'.$this->excel->getActiveSheet()->getHighestRow())->getNumberFormat()->setFormatCode('#,##0.00'); 

		$this->excel->getActiveSheet()->getStyle('C1:C'.$this->excel->getActiveSheet()->getHighestRow())
    	->getAlignment()->setWrapText(true);
    	$this->excel->getActiveSheet()->getStyle('K1:K'.$this->excel->getActiveSheet()->getHighestRow())
    	->getAlignment()->setWrapText(true);

		//set aligment to center for that merged cell (A1 to D1)
		// $this->excel->getActiveSheet()->getStyle('B1:B2')->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
		$this->excel->getActiveSheet()->getStyle('B4:B5')->getFont()->setBold(true);

		$filename= 'Laporan Perangkat Pernah Pakai_'.$date.'.xls'; //save our workbook as this file name
		header('Content-Type: application/vnd.ms-excel'); //mime type
		header('Content-Disposition: attachment;filename="'.$filename.'"'); //tell browser what's the file name
		header('Cache-Control: max-age=0'); //no cache
			             
		//save it to Excel5 format (excel 2003 .XLS file), change this to 'Excel2007' (and adjust the filename extension, also the header mime type)
		//if you want to save it as .XLSX Excel 2007 format
		$objWriter = PHPExcel_IOFactory::createWriter($this->excel, 'Excel5');  
		//force user to download the Excel file without writing it to server's HD
		$objWriter->save('php://output');
	}

	function laporan_peralatan_teknisi()
	{
		
		$x=0;

		$ls_sql	= " SELECT	*
					FROM	pro_barang
					WHERE	lower(jenis_kebutuhan)='teknisi' AND (UPPER(kode_barang) LIKE '%".strtoupper(post('keyword'))."%'
							OR UPPER(nama_barang) LIKE '%".strtoupper(post('keyword'))."%') 
							ORDER BY ".(post('sort')=='' ? 'kode_barang' : post('sort'))." ".(post('order')=='' ? 'asc' : post('order'));	
	
		$ls_sql2	= "	SELECT COUNT(1)
					FROM	pro_barang
					WHERE	lower(jenis_kebutuhan)='teknisi' AND (UPPER(kode_barang) LIKE '%".strtoupper(post('keyword'))."%'
							OR UPPER(nama_barang) LIKE '%".strtoupper(post('keyword'))."%') 
							ORDER BY ".(post('sort')=='' ? 'kode_barang' : post('sort'))." ".(post('order')=='' ? 'asc' : post('order'));
		
		$total = $this->get_data($ls_sql2);

		$result = $this->db->query($ls_sql);

		$data_p = array(	'rows'=> $result->result_array(), 
								'total' => $total);

		$date = date('Y-m-d');

		//load our new PHPExcel library
		$this->load->library('excel');
		//activate worksheet number 1
		$this->excel->setActiveSheetIndex(0);
		//name the worksheet
		$this->excel->getActiveSheet()->setTitle("Peralatan Teknisi");

		$no = 1;

			
		if ($data_p) {

			$styleArrayBorder = array(
				'borders' => array(
					'allborders' => array(
					'style' => PHPExcel_Style_Border::BORDER_THIN
					)
				)
			);

			$this->excel->getActiveSheet()->setCellValue('B8', 'NO');
			$this->excel->getActiveSheet()->setCellValue('C8', 'KODE PERANGKAT');
			$this->excel->getActiveSheet()->setCellValue('D8', 'KODE BARANG');
			$this->excel->getActiveSheet()->setCellValue('E8', 'NAMA BARANG');
			$this->excel->getActiveSheet()->setCellValue('F8', 'NAMA MERK');
			$this->excel->getActiveSheet()->setCellValue('G8', 'SPESIFIKASI');
			$this->excel->getActiveSheet()->setCellValue('H8', 'KONDISI BARANG');
			$this->excel->getActiveSheet()->setCellValue('I8', 'TIPE');
			$this->excel->getActiveSheet()->setCellValue('J8', 'HARGA');
			$this->excel->getActiveSheet()->setCellValue('K8', 'JUMLAH');
			$this->excel->getActiveSheet()->setCellValue('L8', 'KETERANGAN');

			$this->excel->getActiveSheet()->getStyle('B8:L8')->getFont()->setBold(true);
			$this->excel->getActiveSheet()->getStyle('B8:L8')->getFill()->applyFromArray(array('type' => PHPExcel_Style_Fill::FILL_SOLID,'startcolor' => array('rgb' => 'EEEE11')));
			$this->excel->getActiveSheet()->getStyle('B8:L8')->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_CENTER);

			$x = 8;
			$no = 0;

			for($i=0;$i<=$data_p['total']-1;$i++){
				$x++;
				$no++;

				$rows = $data_p['rows'];
				$rows2 = $rows[$i];

				$this->excel->getActiveSheet()->setCellValue('B'.$x, $no);
				$this->excel->getActiveSheet()->getStyle('B'.$x)->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
				$this->excel->getActiveSheet()->setCellValue('C'.$x, $rows2['kode_perangkat']);
				$this->excel->getActiveSheet()->setCellValue('D'.$x, $rows2['kode_barang']);
				$this->excel->getActiveSheet()->setCellValue('E'.$x, $rows2['nama_barang']);
				$this->excel->getActiveSheet()->setCellValue('F'.$x, $rows2['nama_merek']);
				$this->excel->getActiveSheet()->setCellValue('G'.$x, $rows2['spesifikasi']);
				$this->excel->getActiveSheet()->setCellValue('H'.$x, $rows2['kondisi']);
				$this->excel->getActiveSheet()->setCellValue('I'.$x, $rows2['tipe']);
				$this->excel->getActiveSheet()->setCellValue('J'.$x, $rows2['harga']);
				$this->excel->getActiveSheet()->getStyle('J'.$x)->getNumberFormat()->setFormatCode('Rp #,##0'); 
				$this->excel->getActiveSheet()->setCellValue('K'.$x, $rows2['jumlah']);
				$this->excel->getActiveSheet()->getStyle('K'.$x)->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
				$this->excel->getActiveSheet()->setCellValue('L'.$x, $rows2['keterangan']);
				
			}
		}

		$this->excel->getActiveSheet()->setCellValue('B4', strtoupper("Peralatan Teknisi"));
		$this->excel->getActiveSheet()->setCellValue('B5', '('.$date.')');			

		$styleArray = array(
			'borders' => array(
			    'allborders' => array(
			    'style' => PHPExcel_Style_Border::BORDER_THIN
			    )
			),
			'font'  => array(
			    'size'  => 9,
			    'name'  => 'verdana'
			)
		);

		$this->excel->getActiveSheet()->getStyle('B8:L'.$x)->applyFromArray($styleArray);
		unset($styleArray);

		$styleArray1 = array(
		    'font'  => array(
		    'bold'  => true,
		    'uppercase' => true,
		    'size'  => 11,
		    'name'  => 'Calibri'
		    )
		);

		$this->excel->getActiveSheet()->getColumnDimension('B')->setWidth(10);
		$this->excel->getActiveSheet()->getColumnDimension('C')->setWidth(22);
		$this->excel->getActiveSheet()->getColumnDimension('D')->setWidth(22);
		$this->excel->getActiveSheet()->getColumnDimension('E')->setWidth(35);
		$this->excel->getActiveSheet()->getColumnDimension('F')->setWidth(35);
		$this->excel->getActiveSheet()->getColumnDimension('G')->setWidth(22);
		$this->excel->getActiveSheet()->getColumnDimension('H')->setWidth(27);
		$this->excel->getActiveSheet()->getColumnDimension('I')->setWidth(22);
		$this->excel->getActiveSheet()->getColumnDimension('J')->setWidth(30);
		$this->excel->getActiveSheet()->getColumnDimension('K')->setWidth(10);
		$this->excel->getActiveSheet()->getColumnDimension('L')->setWidth(40);

		//$this->excel->getActiveSheet()->getStyle('D1:H'.$this->excel->getActiveSheet()->getHighestRow())->getNumberFormat()->setFormatCode('#,##0.00'); 

		$this->excel->getActiveSheet()->getStyle('C1:C'.$this->excel->getActiveSheet()->getHighestRow())
    	->getAlignment()->setWrapText(true);
    	$this->excel->getActiveSheet()->getStyle('K1:K'.$this->excel->getActiveSheet()->getHighestRow())
    	->getAlignment()->setWrapText(true);

		//set aligment to center for that merged cell (A1 to D1)
		// $this->excel->getActiveSheet()->getStyle('B1:B2')->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
		$this->excel->getActiveSheet()->getStyle('B4:B5')->getFont()->setBold(true);

		$filename= 'Laporan Peralatan Teknisi_'.$date.'.xls'; //save our workbook as this file name
		header('Content-Type: application/vnd.ms-excel'); //mime type
		header('Content-Disposition: attachment;filename="'.$filename.'"'); //tell browser what's the file name
		header('Cache-Control: max-age=0'); //no cache
			             
		//save it to Excel5 format (excel 2003 .XLS file), change this to 'Excel2007' (and adjust the filename extension, also the header mime type)
		//if you want to save it as .XLSX Excel 2007 format
		$objWriter = PHPExcel_IOFactory::createWriter($this->excel, 'Excel5');  
		//force user to download the Excel file without writing it to server's HD
		$objWriter->save('php://output');
	}

	function laporan_peralatan_gedung()
	{
		
		$x=0;

		$ls_sql	= " SELECT	*
					FROM	pro_barang
					WHERE	lower(jenis_kebutuhan)='kebersihan gedung' AND (UPPER(kode_barang) LIKE '%".strtoupper(post('keyword'))."%'
							OR UPPER(nama_barang) LIKE '%".strtoupper(post('keyword'))."%') 
							ORDER BY ".(post('sort')=='' ? 'kode_barang' : post('sort'))." ".(post('order')=='' ? 'asc' : post('order'));	
	
		$ls_sql2	= "	SELECT COUNT(1)
					FROM	pro_barang
					WHERE	lower(jenis_kebutuhan)='kebersihan gedung' AND (UPPER(kode_barang) LIKE '%".strtoupper(post('keyword'))."%'
							OR UPPER(nama_barang) LIKE '%".strtoupper(post('keyword'))."%') 
							ORDER BY ".(post('sort')=='' ? 'kode_barang' : post('sort'))." ".(post('order')=='' ? 'asc' : post('order'));
		
		$total = $this->get_data($ls_sql2);

		$result = $this->db->query($ls_sql);

		$data_p = array(	'rows'=> $result->result_array(), 
								'total' => $total);

		$date = date('Y-m-d');

		//load our new PHPExcel library
		$this->load->library('excel');
		//activate worksheet number 1
		$this->excel->setActiveSheetIndex(0);
		//name the worksheet
		$this->excel->getActiveSheet()->setTitle("Peralatan Kebersihan Gedung");

		$no = 1;

			
		if ($data_p) {

			$styleArrayBorder = array(
				'borders' => array(
					'allborders' => array(
					'style' => PHPExcel_Style_Border::BORDER_THIN
					)
				)
			);

			$this->excel->getActiveSheet()->setCellValue('B8', 'NO');
			$this->excel->getActiveSheet()->setCellValue('C8', 'KODE PERANGKAT');
			$this->excel->getActiveSheet()->setCellValue('D8', 'KODE BARANG');
			$this->excel->getActiveSheet()->setCellValue('E8', 'NAMA BARANG');
			$this->excel->getActiveSheet()->setCellValue('F8', 'NAMA MERK');
			$this->excel->getActiveSheet()->setCellValue('G8', 'SPESIFIKASI');
			$this->excel->getActiveSheet()->setCellValue('H8', 'KONDISI BARANG');
			$this->excel->getActiveSheet()->setCellValue('I8', 'TIPE');
			$this->excel->getActiveSheet()->setCellValue('J8', 'HARGA');
			$this->excel->getActiveSheet()->setCellValue('K8', 'JUMLAH');
			$this->excel->getActiveSheet()->setCellValue('L8', 'KETERANGAN');

			$this->excel->getActiveSheet()->getStyle('B8:L8')->getFont()->setBold(true);
			$this->excel->getActiveSheet()->getStyle('B8:L8')->getFill()->applyFromArray(array('type' => PHPExcel_Style_Fill::FILL_SOLID,'startcolor' => array('rgb' => 'EEEE11')));
			$this->excel->getActiveSheet()->getStyle('B8:L8')->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_CENTER);

			$x = 8;
			$no = 0;

			for($i=0;$i<=$data_p['total']-1;$i++){
				$x++;
				$no++;

				$rows = $data_p['rows'];
				$rows2 = $rows[$i];

				$this->excel->getActiveSheet()->setCellValue('B'.$x, $no);
				$this->excel->getActiveSheet()->getStyle('B'.$x)->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
				$this->excel->getActiveSheet()->setCellValue('C'.$x, $rows2['kode_perangkat']);
				$this->excel->getActiveSheet()->setCellValue('D'.$x, $rows2['kode_barang']);
				$this->excel->getActiveSheet()->setCellValue('E'.$x, $rows2['nama_barang']);
				$this->excel->getActiveSheet()->setCellValue('F'.$x, $rows2['nama_merek']);
				$this->excel->getActiveSheet()->setCellValue('G'.$x, $rows2['spesifikasi']);
				$this->excel->getActiveSheet()->setCellValue('H'.$x, $rows2['kondisi']);
				$this->excel->getActiveSheet()->setCellValue('I'.$x, $rows2['tipe']);
				$this->excel->getActiveSheet()->setCellValue('J'.$x, $rows2['harga']);
				$this->excel->getActiveSheet()->getStyle('J'.$x)->getNumberFormat()->setFormatCode('Rp #,##0'); 
				$this->excel->getActiveSheet()->setCellValue('K'.$x, $rows2['jumlah']);
				$this->excel->getActiveSheet()->getStyle('K'.$x)->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
				$this->excel->getActiveSheet()->setCellValue('L'.$x, $rows2['keterangan']);

				

			}
		}

		$this->excel->getActiveSheet()->setCellValue('B4', strtoupper("Peralatan Kebersihan Gedung"));
		$this->excel->getActiveSheet()->setCellValue('B5', '('.$date.')');			

		$styleArray = array(
			'borders' => array(
			    'allborders' => array(
			    'style' => PHPExcel_Style_Border::BORDER_THIN
			    )
			),
			'font'  => array(
			    'size'  => 9,
			    'name'  => 'verdana'
			)
		);

		$this->excel->getActiveSheet()->getStyle('B8:L'.$x)->applyFromArray($styleArray);
		unset($styleArray);

		$styleArray1 = array(
		    'font'  => array(
		    'bold'  => true,
		    'uppercase' => true,
		    'size'  => 11,
		    'name'  => 'Calibri'
		    )
		);

		$this->excel->getActiveSheet()->getColumnDimension('C')->setWidth(10);
		$this->excel->getActiveSheet()->getColumnDimension('C')->setWidth(22);
		$this->excel->getActiveSheet()->getColumnDimension('D')->setWidth(22);
		$this->excel->getActiveSheet()->getColumnDimension('E')->setWidth(35);
		$this->excel->getActiveSheet()->getColumnDimension('F')->setWidth(35);
		$this->excel->getActiveSheet()->getColumnDimension('G')->setWidth(22);
		$this->excel->getActiveSheet()->getColumnDimension('H')->setWidth(27);
		$this->excel->getActiveSheet()->getColumnDimension('I')->setWidth(22);
		$this->excel->getActiveSheet()->getColumnDimension('J')->setWidth(30);
		$this->excel->getActiveSheet()->getColumnDimension('K')->setWidth(10);
		$this->excel->getActiveSheet()->getColumnDimension('L')->setWidth(40);

		//$this->excel->getActiveSheet()->getStyle('D1:H'.$this->excel->getActiveSheet()->getHighestRow())->getNumberFormat()->setFormatCode('#,##0.00'); 

		$this->excel->getActiveSheet()->getStyle('C1:C'.$this->excel->getActiveSheet()->getHighestRow())
    	->getAlignment()->setWrapText(true);
    	$this->excel->getActiveSheet()->getStyle('K1:K'.$this->excel->getActiveSheet()->getHighestRow())
    	->getAlignment()->setWrapText(true);

		//set aligment to center for that merged cell (A1 to D1)
		// $this->excel->getActiveSheet()->getStyle('B1:B2')->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
		$this->excel->getActiveSheet()->getStyle('B4:B5')->getFont()->setBold(true);

		$filename= 'Laporan Peralatan Kebersihan Gedung_'.$date.'.xls'; //save our workbook as this file name
		header('Content-Type: application/vnd.ms-excel'); //mime type
		header('Content-Disposition: attachment;filename="'.$filename.'"'); //tell browser what's the file name
		header('Cache-Control: max-age=0'); //no cache
			             
		//save it to Excel5 format (excel 2003 .XLS file), change this to 'Excel2007' (and adjust the filename extension, also the header mime type)
		//if you want to save it as .XLSX Excel 2007 format
		$objWriter = PHPExcel_IOFactory::createWriter($this->excel, 'Excel5');  
		//force user to download the Excel file without writing it to server's HD
		$objWriter->save('php://output');
	}

	function laporan_peralatan_kebun()
	{
		
		$x=0;

		$ls_sql	= " SELECT	*
					FROM	pro_barang
					WHERE	lower(jenis_kebutuhan)='kebersihan kebun/taman' AND (UPPER(kode_barang) LIKE '%".strtoupper(post('keyword'))."%'
							OR UPPER(nama_barang) LIKE '%".strtoupper(post('keyword'))."%') 
							ORDER BY ".(post('sort')=='' ? 'kode_barang' : post('sort'))." ".(post('order')=='' ? 'asc' : post('order'));	
	
		$ls_sql2	= "	SELECT COUNT(1)
					FROM	pro_barang
					WHERE	lower(jenis_kebutuhan)='kebersihan kebun/taman' AND (UPPER(kode_barang) LIKE '%".strtoupper(post('keyword'))."%'
							OR UPPER(nama_barang) LIKE '%".strtoupper(post('keyword'))."%') 
							ORDER BY ".(post('sort')=='' ? 'kode_barang' : post('sort'))." ".(post('order')=='' ? 'asc' : post('order'));
		
		$total = $this->get_data($ls_sql2);

		$result = $this->db->query($ls_sql);

		$data_p = array(	'rows'=> $result->result_array(), 
								'total' => $total);

		$date = date('Y-m-d');

		//load our new PHPExcel library
		$this->load->library('excel');
		//activate worksheet number 1
		$this->excel->setActiveSheetIndex(0);
		//name the worksheet
		$this->excel->getActiveSheet()->setTitle("Peralatan Kebersihan Kebun");

		$no = 1;

			
		if ($data_p) {

			$styleArrayBorder = array(
				'borders' => array(
					'allborders' => array(
					'style' => PHPExcel_Style_Border::BORDER_THIN
					)
				)
			);

			$this->excel->getActiveSheet()->setCellValue('B8', 'NO');
			$this->excel->getActiveSheet()->setCellValue('C8', 'KODE PERANGKAT');
			$this->excel->getActiveSheet()->setCellValue('D8', 'KODE BARANG');
			$this->excel->getActiveSheet()->setCellValue('E8', 'NAMA BARANG');
			$this->excel->getActiveSheet()->setCellValue('F8', 'NAMA MERK');
			$this->excel->getActiveSheet()->setCellValue('G8', 'SPESIFIKASI');
			$this->excel->getActiveSheet()->setCellValue('H8', 'KONDISI BARANG');
			$this->excel->getActiveSheet()->setCellValue('I8', 'TIPE');
			$this->excel->getActiveSheet()->setCellValue('J8', 'HARGA');
			$this->excel->getActiveSheet()->setCellValue('K8', 'JUMLAH');
			$this->excel->getActiveSheet()->setCellValue('L8', 'KETERANGAN');

			$this->excel->getActiveSheet()->getStyle('B8:L8')->getFont()->setBold(true);
			$this->excel->getActiveSheet()->getStyle('B8:L8')->getFill()->applyFromArray(array('type' => PHPExcel_Style_Fill::FILL_SOLID,'startcolor' => array('rgb' => 'EEEE11')));
			$this->excel->getActiveSheet()->getStyle('B8:L8')->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_CENTER);

			$x = 8;
			$no = 0;

			for($i=0;$i<=$data_p['total']-1;$i++){
				$x++;
				$no++;

				$rows = $data_p['rows'];
				$rows2 = $rows[$i];

				$this->excel->getActiveSheet()->setCellValue('B'.$x, $no);
				$this->excel->getActiveSheet()->getStyle('B'.$x)->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
				$this->excel->getActiveSheet()->setCellValue('C'.$x, $rows2['kode_perangkat']);
				$this->excel->getActiveSheet()->setCellValue('D'.$x, $rows2['kode_barang']);
				$this->excel->getActiveSheet()->setCellValue('E'.$x, $rows2['nama_barang']);
				$this->excel->getActiveSheet()->setCellValue('F'.$x, $rows2['nama_merek']);
				$this->excel->getActiveSheet()->setCellValue('G'.$x, $rows2['spesifikasi']);
				$this->excel->getActiveSheet()->setCellValue('H'.$x, $rows2['kondisi']);
				$this->excel->getActiveSheet()->setCellValue('I'.$x, $rows2['tipe']);
				$this->excel->getActiveSheet()->setCellValue('J'.$x, $rows2['harga']);
				$this->excel->getActiveSheet()->getStyle('J'.$x)->getNumberFormat()->setFormatCode('Rp #,##0'); 
				$this->excel->getActiveSheet()->setCellValue('K'.$x, $rows2['jumlah']);
				$this->excel->getActiveSheet()->getStyle('K'.$x)->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
				$this->excel->getActiveSheet()->setCellValue('L'.$x, $rows2['keterangan']);
			}
		}

		$this->excel->getActiveSheet()->setCellValue('B4', strtoupper("Peralatan Kebersihan Kebun/Taman"));
		$this->excel->getActiveSheet()->setCellValue('B5', '('.$date.')');			

		$styleArray = array(
			'borders' => array(
			    'allborders' => array(
			    'style' => PHPExcel_Style_Border::BORDER_THIN
			    )
			),
			'font'  => array(
			    'size'  => 9,
			    'name'  => 'verdana'
			)
		);

		$this->excel->getActiveSheet()->getStyle('B8:L'.$x)->applyFromArray($styleArray);
		unset($styleArray);

		$styleArray1 = array(
		    'font'  => array(
		    'bold'  => true,
		    'uppercase' => true,
		    'size'  => 11,
		    'name'  => 'Calibri'
		    )
		);

		$this->excel->getActiveSheet()->getColumnDimension('B')->setWidth(10);
		$this->excel->getActiveSheet()->getColumnDimension('C')->setWidth(22);
		$this->excel->getActiveSheet()->getColumnDimension('D')->setWidth(22);
		$this->excel->getActiveSheet()->getColumnDimension('E')->setWidth(35);
		$this->excel->getActiveSheet()->getColumnDimension('F')->setWidth(35);
		$this->excel->getActiveSheet()->getColumnDimension('G')->setWidth(22);
		$this->excel->getActiveSheet()->getColumnDimension('H')->setWidth(27);
		$this->excel->getActiveSheet()->getColumnDimension('I')->setWidth(22);
		$this->excel->getActiveSheet()->getColumnDimension('J')->setWidth(30);
		$this->excel->getActiveSheet()->getColumnDimension('K')->setWidth(10);
		$this->excel->getActiveSheet()->getColumnDimension('L')->setWidth(30);

		//$this->excel->getActiveSheet()->getStyle('D1:H'.$this->excel->getActiveSheet()->getHighestRow())->getNumberFormat()->setFormatCode('#,##0.00'); 

		$this->excel->getActiveSheet()->getStyle('C1:C'.$this->excel->getActiveSheet()->getHighestRow())
    	->getAlignment()->setWrapText(true);
    	$this->excel->getActiveSheet()->getStyle('K1:K'.$this->excel->getActiveSheet()->getHighestRow())
    	->getAlignment()->setWrapText(true);

		//set aligment to center for that merged cell (A1 to D1)
		// $this->excel->getActiveSheet()->getStyle('B1:B2')->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
		$this->excel->getActiveSheet()->getStyle('B4:B5')->getFont()->setBold(true);

		$filename= 'Laporan Peralatan Kebersihan Kebun_'.$date.'.xls'; //save our workbook as this file name
		header('Content-Type: application/vnd.ms-excel'); //mime type
		header('Content-Disposition: attachment;filename="'.$filename.'"'); //tell browser what's the file name
		header('Cache-Control: max-age=0'); //no cache
			             
		//save it to Excel5 format (excel 2003 .XLS file), change this to 'Excel2007' (and adjust the filename extension, also the header mime type)
		//if you want to save it as .XLSX Excel 2007 format
		$objWriter = PHPExcel_IOFactory::createWriter($this->excel, 'Excel5');  
		//force user to download the Excel file without writing it to server's HD
		$objWriter->save('php://output');
	}

	function laporan_permintaan()
	{
		$id=get('id_permintaan');
		$x=0;

		$ls_sql	=  "SELECT
					a.ID_PERMINTAAN,
					a.TANGGAL,
					a.NAMA,
					--a.DEPARTEMEN,--
					b.NAMA_DEPARTEMEN as DEPARTEMEN,
					a.PERMOHONAN_MASALAH,
					a.PILIHAN_PERMINTAAN
					FROM	PRO_DATA_PERMINTAAN_PERANGKAT a
					left join HRD_DEPARTEMEN b
					on a.DEPARTEMEN = b.ID_DEPARTEMEN_PK
					WHERE	ID_PERMINTAAN = '$id' AND 
							(UPPER(a.TANGGAL) LIKE '%".strtoupper(post('keyword'))."%'
							OR UPPER(a.NAMA) LIKE '%".strtoupper(post('keyword'))."%'
							OR UPPER(b.NAMA_DEPARTEMEN) LIKE '%".strtoupper(post('keyword'))."%'
							OR UPPER(a.PERMOHONAN_MASALAH) LIKE '%".strtoupper(post('keyword'))."%'
							OR UPPER(a.PILIHAN_PERMINTAAN) LIKE '%".strtoupper(post('keyword'))."%')
					ORDER BY ".(post('sort')=='' ? 'a.ID_PERMINTAAN' : post('sort'))." ".(post('order')=='' ? 'asc' : post('order'));	

		$ls_sql2	= "	SELECT 	COUNT(1)
						FROM	PRO_DATA_PERMINTAAN_PERANGKAT a
						left join HRD_DEPARTEMEN b
						on a.DEPARTEMEN = b.ID_DEPARTEMEN_PK
						WHERE	ID_PERMINTAAN = '$id' AND 
								(UPPER(a.TANGGAL) LIKE '%".strtoupper(post('keyword'))."%'
								OR UPPER(a.NAMA) LIKE '%".strtoupper(post('keyword'))."%'
								OR UPPER(b.NAMA_DEPARTEMEN) LIKE '%".strtoupper(post('keyword'))."%'
								OR UPPER(a.PERMOHONAN_MASALAH) LIKE '%".strtoupper(post('keyword'))."%'
								OR UPPER(a.PILIHAN_PERMINTAAN) LIKE '%".strtoupper(post('keyword'))."%')
						ORDER BY ".(post('sort')=='' ? 'a.ID_PERMINTAAN' : post('sort'))." ".(post('order')=='' ? 'asc' : post('order'));	

		$total = $this->get_data($ls_sql2);

		$result = $this->db->query($ls_sql);

		$data_p = array(	'rows'=> $result->result_array(), 
								'total' => $total);

		$ls_sql3 = "	SELECT
							ROWNUM as no,
							a.ID_PERMINTAAN_DTL,
							a.ID_PERMINTAAN,
							a.id_barang,
							b.NAMA_BARANG,
							a.JUMLAH,
							a.LOKASI,
							a.KETERANGAN
							FROM
							PRO_DATA_PERMINTAAN_PRK_DTL a
							left join PRO_SETUP_STOCK b
							on a.id_barang = b.KODE_BARANG
							WHERE a.ID_PERMINTAAN = $id
							and	(UPPER(b.NAMA_BARANG) LIKE '%".strtoupper(post('keyword'))."%'
							OR UPPER(a.LOKASI) LIKE '%".strtoupper(post('keyword'))."%'
							OR UPPER(a.KETERANGAN) LIKE '%".strtoupper(post('keyword'))."%')
							ORDER BY ".(post('sort')=='' ? 'a.ID_PERMINTAAN_DTL' : post('sort'))." ".(post('order')=='' ? 'asc' : post('order'));	

		$ls_sql4 = "	SELECT COUNT(1)
							FROM
							PRO_DATA_PERMINTAAN_PRK_DTL a
							left join PRO_SETUP_STOCK b
							on a.id_barang = b.KODE_BARANG
							WHERE a.ID_PERMINTAAN = $id
							and	(UPPER(b.NAMA_BARANG) LIKE '%".strtoupper(post('keyword'))."%'
							OR UPPER(a.LOKASI) LIKE '%".strtoupper(post('keyword'))."%'
							OR UPPER(a.KETERANGAN) LIKE '%".strtoupper(post('keyword'))."%')
					ORDER BY ".(post('sort')=='' ? 'a.ID_PERMINTAAN_DTL' : post('sort'))." ".(post('order')=='' ? 'asc' : post('order'));	

		$total1 = $this->get_data($ls_sql4);

		$result1 = $this->db->query($ls_sql3);

		$data_p1 = array(	'rowsd'=> $result1->result_array(), 
								'totald' => $total1);

		$date = date('d M Y');

		//load our new PHPExcel library
		$this->load->library('excel');
		//activate worksheet number 1
		$this->excel->setActiveSheetIndex(0);
		//name the worksheet
		$this->excel->getActiveSheet()->setTitle("Laporan Permintaan");

		$no = 1;

		if ($data_p) {

			$styleArrayBorder = array(
				'borders' => array(
					'allborders' => array(
					'style' => PHPExcel_Style_Border::BORDER_THIN
					)
				)
			);

			$styleArrayUnderline = array(
			 'font' => array(
			 'underline' => PHPExcel_Style_Font::UNDERLINE_SINGLE,
			 'name' => 'Calibri',
			 'size' => 11,
			 'bold' => true
			 )
			);

			$styleArrayDefault = array(
			 'font' => array(
			 'name' => 'Calibri',
			 'size' => 11,
			 )
			);

			$styleArrayItalic = array(
			 'font' => array(
			 'name' => 'Calibri',
			 'size' => 11,
			 'italic' => true
			 )
			);

			$styleArrayFont = array(
			 'font' => array(
			 'name' => 'Calibri',
			 'size' => 15,
			 'bold' => true,
			 'italic' => true
			 )
			);

			$styleArrayFont1 = array(
			 'font' => array(
			 'name' => 'Calibri',
			 'size' => 12,
			 'bold' => true,
			 'italic' => true
			 )
			);

			$rows = $data_p['rows'];
			$rows2 = $rows[0];



			$this->excel->getActiveSheet()->setCellValue('A2', strtoupper('FORM TECHNICAL SUPPORT'));
			$this->excel->getActiveSheet()->getStyle('A2')->applyFromArray($styleArrayFont);
			$this->excel->getActiveSheet()->setCellValue('A3', 'Building Managament & Mtc Dept.');
			$this->excel->getActiveSheet()->getStyle('A3')->applyFromArray($styleArrayFont1);
			
			$this->excel->getActiveSheet()->setCellValue('A5', 'ID Permintaan Perangkat');
			$this->excel->getActiveSheet()->setCellValue('D5', ': '.$rows2['id_permintaan']);	
			$this->excel->getActiveSheet()->setCellValue('A6', 'Tanggal');
			$this->excel->getActiveSheet()->setCellValue('D6', ': '.$rows2['tanggal']);
			$this->excel->getActiveSheet()->setCellValue('A7', 'Informasi Pemohon :');
			$this->excel->getActiveSheet()->getStyle('A7')->getFont()->setBold(true);
			$this->excel->getActiveSheet()->setCellValue('A8', 'Nama');
			$this->excel->getActiveSheet()->setCellValue('D8', ': '.$rows2['nama']);
			$this->excel->getActiveSheet()->setCellValue('A9', 'Departement');
			$this->excel->getActiveSheet()->setCellValue('D9', ': '.$rows2['departemen']);

			$this->excel->getActiveSheet()->setCellValue('A10', 'Pilih Permintaan Anda :');
			$this->excel->getActiveSheet()->getStyle('A10')->getFont()->setBold(true);

			$data_explode = $rows2['pilihan_permintaan'];

			$data_pilihan = explode(",",$data_explode);

			$this->excel->getActiveSheet()->setCellValue('C12', 'Perbaikan');
			$this->excel->getActiveSheet()->setCellValue('C14', 'Pembelian/Pengadaan Baru');
			$this->excel->getActiveSheet()->setCellValue('C16', 'Penggantian Baru');

			if($data_pilihan[0]==NULL) {
				$this->excel->getActiveSheet()->setCellValue('B12', ' ');
			} else {
				$this->excel->getActiveSheet()->setCellValue('B12', 'V');
			}if($data_pilihan[2]==NULL) {
				$this->excel->getActiveSheet()->setCellValue('B14', ' ');
			} else {
				$this->excel->getActiveSheet()->setCellValue('B14', 'V');
			}if($data_pilihan[4]==NULL) {
				$this->excel->getActiveSheet()->setCellValue('B16', ' ');
			} else {
				$this->excel->getActiveSheet()->setCellValue('B16', 'V');
			}

			//$this->excel->getActiveSheet()->setCellValue('J30', '-'.$data_pilihan[0].'-'.$data_pilihan[1].'-'.$data_pilihan[2].'-'.$data_pilihan[3].'-'.$data_pilihan[4].'-'.$data_pilihan[5]);

			$this->excel->getActiveSheet()->getStyle('B12:B16')->getFont()->setBold(true);

			$this->excel->getActiveSheet()->getStyle('B12')->applyFromArray($styleArrayBorder);
			$this->excel->getActiveSheet()->getStyle('B14')->applyFromArray($styleArrayBorder);
			$this->excel->getActiveSheet()->getStyle('B16')->applyFromArray($styleArrayBorder);
			
			$this->excel->getActiveSheet()->setCellValue('F12', 'Penambahan');
			$this->excel->getActiveSheet()->setCellValue('F14', 'Pemeliharaan');
			$this->excel->getActiveSheet()->setCellValue('F16', 'Peminjaman Alat');

			if($data_pilihan[1]==NULL) {
				$this->excel->getActiveSheet()->setCellValue('E12', ' ');
			} else {
				$this->excel->getActiveSheet()->setCellValue('E12', 'V');
			}if($data_pilihan[3]==NULL) {
				$this->excel->getActiveSheet()->setCellValue('E14', ' ');
			} else {
				$this->excel->getActiveSheet()->setCellValue('E14', 'V');
			}if($data_pilihan[5]==NULL) {
				$this->excel->getActiveSheet()->setCellValue('E16', ' ');
			} else {
				$this->excel->getActiveSheet()->setCellValue('E16', 'V');
			}

			$this->excel->getActiveSheet()->getStyle('E12:E16')->getFont()->setBold(true);

			$this->excel->getActiveSheet()->getStyle('E12')->applyFromArray($styleArrayBorder);
			$this->excel->getActiveSheet()->getStyle('E14')->applyFromArray($styleArrayBorder);
			$this->excel->getActiveSheet()->getStyle('E16')->applyFromArray($styleArrayBorder);
			
			$this->excel->getActiveSheet()->getStyle('B12:B16')->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
			$this->excel->getActiveSheet()->getStyle('B12:B16')->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::VERTICAL_CENTER);

			$this->excel->getActiveSheet()->getStyle('E12:E16')->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
			$this->excel->getActiveSheet()->getStyle('E12:E16')->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::VERTICAL_CENTER);

			$this->excel->getActiveSheet()->setCellValue('A18', 'Silahkan sebutkan permohonan atau menjelaskan masalah yang terjadi : ');
			$this->excel->getActiveSheet()->getStyle('A18')->getFont()->setBold(true);

			$this->excel->getActiveSheet()->setCellValue('C20','- '.$rows2['permohonan_masalah']);
			$this->excel->getActiveSheet()->getStyle('C20:H20')->applyFromArray($styleArrayBorder);
			$this->excel->getActiveSheet()->mergeCells('C20:H20');

			$this->excel->getActiveSheet()->setCellValue('B22', 'Daftar barang (sesuai list permintaan) : ');
			$this->excel->getActiveSheet()->getStyle('B22')->getFont()->setBold(true);

			$this->excel->getActiveSheet()->getStyle('C24:H24')->getFill()->applyFromArray(array('type' => PHPExcel_Style_Fill::FILL_SOLID,'startcolor' => array('rgb' => 'B2B2B2')));
			$this->excel->getActiveSheet()->getStyle('C24:H24')->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
			
			$this->excel->getActiveSheet()->setCellValue('C24', 'ID DETAIL');
			$this->excel->getActiveSheet()->setCellValue('D24', 'ID BARANG');
			$this->excel->getActiveSheet()->setCellValue('E24', 'JUMLAH');
			$this->excel->getActiveSheet()->mergeCells('E24:F24');
			$this->excel->getActiveSheet()->setCellValue('G24', 'LOKASI');
			$this->excel->getActiveSheet()->setCellValue('H24', 'KETERANGAN');	

			$x = 24;

			for($i=0;$i<=$data_p1['totald']-1;$i++){
				$x++;
				$y = $x + 8;

			$rows3	=	$data_p1['rowsd'];
			$rows4	=	$rows3[$i];

				$this->excel->getActiveSheet()->setCellValue('C'.$x, $rows4['id_permintaan_dtl']);
				$this->excel->getActiveSheet()->setCellValue('D'.$x, $rows4['id_barang']);
				$this->excel->getActiveSheet()->setCellValue('E'.$x, $rows4['jumlah']);
				$this->excel->getActiveSheet()->mergeCells('E'.$x.':F'.$x);
				$this->excel->getActiveSheet()->setCellValue('G'.$x, $rows4['lokasi']);
				$this->excel->getActiveSheet()->setCellValue('H'.$x, $rows4['keterangan']);

			}
				$this->excel->getActiveSheet()->setCellValue('C'.$y, '(                                               )');
				$this->excel->getActiveSheet()->mergeCells('C'.$y.':D'.$y);
				$this->excel->getActiveSheet()->getStyle('C'.$y.':D'.$y)->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
				$this->excel->getActiveSheet()->setCellValue('G'.$y, '(                                               )');
				$this->excel->getActiveSheet()->mergeCells('G'.$y.':H'.$y);
				$this->excel->getActiveSheet()->getStyle('G'.$y.':H'.$y)->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_CENTER);

			$this->excel->getActiveSheet()->getStyle('C24:H'.$x)->applyFromArray($styleArrayBorder);
			// $this->excel->getActiveSheet()->getStyle('E45:I45')->applyFromArray($styleArrayUnderline);
			// $this->excel->getActiveSheet()->getStyle('E39:I46')->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_CENTER);

		}

		$this->excel->getActiveSheet()->getColumnDimension('A')->setWidth(3);
		$this->excel->getActiveSheet()->getColumnDimension('B')->setWidth(3);
		$this->excel->getActiveSheet()->getColumnDimension('C')->setWidth(17.60);
		$this->excel->getActiveSheet()->getColumnDimension('D')->setWidth(13);
		//$this->excel->getActiveSheet()->getRowDimension('17')->setRowHeight(80);
		$this->excel->getActiveSheet()->getColumnDimension('E')->setWidth(3);
		$this->excel->getActiveSheet()->getColumnDimension('F')->setWidth(8.43);
		$this->excel->getActiveSheet()->getColumnDimension('G')->setWidth(17);
		$this->excel->getActiveSheet()->getColumnDimension('H')->setWidth(18.80);
/*
		$this->excel->getActiveSheet()->getStyle('D1:C'.$this->excel->getActiveSheet()->getHighestRow())->getNumberFormat()->setFormatCode('#,##0.00'); 

		$this->excel->getActiveSheet()->getStyle('C1:C'.$this->excel->getActiveSheet()->getHighestRow())
    	->getAlignment()->setWrapText(true);
    	$this->excel->getActiveSheet()->getStyle('G1:G'.$this->excel->getActiveSheet()->getHighestRow())
    	->getAlignment()->setWrapText(true);*/

		//set aligment to center for that merged cell (A1 to D1)
		// $this->excel->getActiveSheet()->getStyle('B1:B2')->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
		//$this->excel->getActiveSheet()->getStyle('B4:B5')->getFont()->setBold(true);

		$filename= 'Laporan Permintaan_'.$rows2['nama'].'.xls'; //save our workbook as this file name
		header('Content-Type: application/vnd.ms-excel'); //mime type
		header('Content-Disposition: attachment;filename="'.$filename.'"'); //tell browser what's the file name
		header('Cache-Control: max-age=0'); //no cache
			             
		//save it to Excel5 format (excel 2003 .XLS file), change this to 'Excel2007' (and adjust the filename extension, also the header mime type)
		//if you want to save it as .XLSX Excel 2007 format
		$objWriter = PHPExcel_IOFactory::createWriter($this->excel, 'Excel5');  
		//force user to download the Excel file without writing it to server's HD
		$objWriter->save('php://output');
	}

	function laporan_penambahan()
	{
		$id=get('id_penambahan');
		$x=0;

		$ls_sql	=  "SELECT
					a.id_penambahan,
					a.TANGGAL,
					a.NAMA,
					--a.DEPARTEMEN,--
					b.NAMA_DEPARTEMEN as DEPARTEMEN,
					a.PERMOHONAN_MASALAH,
					a.PILIHAN_PENAMBAHAN
					FROM	PRO_DATA_PENAMBAHAN_PERANGKAT a
					left join HRD_DEPARTEMEN b
					on a.DEPARTEMEN = b.ID_DEPARTEMEN_PK
					WHERE	id_penambahan = '$id' AND 
							(UPPER(a.TANGGAL) LIKE '%".strtoupper(post('keyword'))."%'
							OR UPPER(a.NAMA) LIKE '%".strtoupper(post('keyword'))."%'
							OR UPPER(b.NAMA_DEPARTEMEN) LIKE '%".strtoupper(post('keyword'))."%'
							OR UPPER(a.PERMOHONAN_MASALAH) LIKE '%".strtoupper(post('keyword'))."%'
							OR UPPER(a.PILIHAN_PENAMBAHAN) LIKE '%".strtoupper(post('keyword'))."%')
					ORDER BY ".(post('sort')=='' ? 'a.id_penambahan' : post('sort'))." ".(post('order')=='' ? 'asc' : post('order'));	

		$ls_sql2	= "	SELECT 	COUNT(1)
						FROM	PRO_DATA_PENAMBAHAN_PERANGKAT a
						left join HRD_DEPARTEMEN b on a.DEPARTEMEN = b.ID_DEPARTEMEN_PK
						WHERE	id_penambahan = '$id' AND 
								(UPPER(a.TANGGAL) LIKE '%".strtoupper(post('keyword'))."%'
								OR UPPER(a.NAMA) LIKE '%".strtoupper(post('keyword'))."%'
								OR UPPER(b.NAMA_DEPARTEMEN) LIKE '%".strtoupper(post('keyword'))."%'
								OR UPPER(a.PERMOHONAN_MASALAH) LIKE '%".strtoupper(post('keyword'))."%'
								OR UPPER(a.PILIHAN_PENAMBAHAN) LIKE '%".strtoupper(post('keyword'))."%')
						ORDER BY ".(post('sort')=='' ? 'a.id_penambahan' : post('sort'))." ".(post('order')=='' ? 'asc' : post('order'));	

		$total = $this->get_data($ls_sql2);

		$result = $this->db->query($ls_sql);

		$data_p = array(	'rows'=> $result->result_array(), 
								'total' => $total);

		$ls_sql3 = "	SELECT
							ROWNUM as no,
							a.id_penambahan_dtl,
							a.id_penambahan,
							a.id_barang,
							b.NAMA_BARANG,
							a.JUMLAH,
							a.LOKASI,
							a.KETERANGAN
							FROM
							PRO_DATA_PENAMBAHAN_PRK_DTL a
							left join PRO_SETUP_STOCK b	on a.id_barang = b.KODE_BARANG
							WHERE a.id_penambahan = $id
							and	(UPPER(b.NAMA_BARANG) LIKE '%".strtoupper(post('keyword'))."%'
							OR UPPER(a.LOKASI) LIKE '%".strtoupper(post('keyword'))."%'
							OR UPPER(a.KETERANGAN) LIKE '%".strtoupper(post('keyword'))."%')
							ORDER BY ".(post('sort')=='' ? 'a.id_penambahan_dtl' : post('sort'))." ".(post('order')=='' ? 'asc' : post('order'));	

		$ls_sql4 = "	SELECT COUNT(1)
							FROM
							PRO_DATA_PENAMBAHAN_PRK_DTL a
							left join PRO_SETUP_STOCK b
							on a.id_barang = b.KODE_BARANG
							WHERE a.id_penambahan = $id
							and	(UPPER(b.NAMA_BARANG) LIKE '%".strtoupper(post('keyword'))."%'
							OR UPPER(a.LOKASI) LIKE '%".strtoupper(post('keyword'))."%'
							OR UPPER(a.KETERANGAN) LIKE '%".strtoupper(post('keyword'))."%')
					ORDER BY ".(post('sort')=='' ? 'a.id_penambahan_dtl' : post('sort'))." ".(post('order')=='' ? 'asc' : post('order'));	

		$total1 = $this->get_data($ls_sql4);

		$result1 = $this->db->query($ls_sql3);

		$data_p1 = array(	'rowsd'=> $result1->result_array(), 
								'totald' => $total1);

		$date = date('d M Y');

		//load our new PHPExcel library
		$this->load->library('excel');
		//activate worksheet number 1
		$this->excel->setActiveSheetIndex(0);
		//name the worksheet
		$this->excel->getActiveSheet()->setTitle("Laporan Penambahan");

		$no = 1;

		if ($data_p) {

			$styleArrayBorder = array(
				'borders' => array(
					'allborders' => array(
					'style' => PHPExcel_Style_Border::BORDER_THIN
					)
				)
			);

			$styleArrayUnderline = array(
			 'font' => array(
			 'underline' => PHPExcel_Style_Font::UNDERLINE_SINGLE,
			 'name' => 'Calibri',
			 'size' => 11,
			 'bold' => true
			 )
			);

			$styleArrayDefault = array(
			 'font' => array(
			 'name' => 'Calibri',
			 'size' => 11,
			 )
			);

			$styleArrayItalic = array(
			 'font' => array(
			 'name' => 'Calibri',
			 'size' => 11,
			 'italic' => true
			 )
			);

			$styleArrayFont = array(
			 'font' => array(
			 'name' => 'Calibri',
			 'size' => 15,
			 'bold' => true,
			 'italic' => true
			 )
			);

			$styleArrayFont1 = array(
			 'font' => array(
			 'name' => 'Calibri',
			 'size' => 12,
			 'bold' => true,
			 'italic' => true
			 )
			);

			$rows = $data_p['rows'];
			$rows2 = $rows[0];



			$this->excel->getActiveSheet()->setCellValue('A2', strtoupper('FORM TECHNICAL SUPPORT'));
			$this->excel->getActiveSheet()->getStyle('A2')->applyFromArray($styleArrayFont);
			$this->excel->getActiveSheet()->setCellValue('A3', 'Building Managament & Mtc Dept.');
			$this->excel->getActiveSheet()->getStyle('A3')->applyFromArray($styleArrayFont1);
			
			$this->excel->getActiveSheet()->setCellValue('A5', 'ID Penambahan Perangkat');
			$this->excel->getActiveSheet()->setCellValue('D5', ': '.$rows2['id_penambahan']);	
			$this->excel->getActiveSheet()->setCellValue('A6', 'Tanggal');
			$this->excel->getActiveSheet()->setCellValue('D6', ': '.$rows2['tanggal']);
			$this->excel->getActiveSheet()->setCellValue('A7', 'Informasi Pemohon :');
			$this->excel->getActiveSheet()->getStyle('A7')->getFont()->setBold(true);
			$this->excel->getActiveSheet()->setCellValue('A8', 'Nama');
			$this->excel->getActiveSheet()->setCellValue('D8', ': '.$rows2['nama']);
			$this->excel->getActiveSheet()->setCellValue('A9', 'Departement');
			$this->excel->getActiveSheet()->setCellValue('D9', ': '.$rows2['departemen']);

			$this->excel->getActiveSheet()->setCellValue('A10', 'Pilih Penambahan Anda :');
			$this->excel->getActiveSheet()->getStyle('A10')->getFont()->setBold(true);

			$data_explode = $rows2['pilihan_penambahan'];

			$data_pilihan = explode(",",$data_explode);

			

			$this->excel->getActiveSheet()->setCellValue('C12', 'Perbaikan');
			$this->excel->getActiveSheet()->setCellValue('C14', 'Pembelian/Pengadaan Baru');
			$this->excel->getActiveSheet()->setCellValue('C16', 'Penggantian Baru');

			if($data_pilihan[0]==NULL) {
				$this->excel->getActiveSheet()->setCellValue('B12', ' ');
			} else {
				$this->excel->getActiveSheet()->setCellValue('B12', 'V');
			}if($data_pilihan[2]==NULL) {
				$this->excel->getActiveSheet()->setCellValue('B14', ' ');
			} else {
				$this->excel->getActiveSheet()->setCellValue('B14', 'V');
			}if($data_pilihan[4]==NULL) {
				$this->excel->getActiveSheet()->setCellValue('B16', ' ');
			} else {
				$this->excel->getActiveSheet()->setCellValue('B16', 'V');
			}

			
			$this->excel->getActiveSheet()->getStyle('B12:B16')->getFont()->setBold(true);

			$this->excel->getActiveSheet()->getStyle('B12')->applyFromArray($styleArrayBorder);
			$this->excel->getActiveSheet()->getStyle('B14')->applyFromArray($styleArrayBorder);
			$this->excel->getActiveSheet()->getStyle('B16')->applyFromArray($styleArrayBorder);
			
			$this->excel->getActiveSheet()->setCellValue('F12', 'Penambahan');
			$this->excel->getActiveSheet()->setCellValue('F14', 'Pemeliharaan');
			$this->excel->getActiveSheet()->setCellValue('F16', 'Peminjaman Alat');

			if($data_pilihan[1]==NULL) {
				$this->excel->getActiveSheet()->setCellValue('E12', ' ');
			} else {
				$this->excel->getActiveSheet()->setCellValue('E12', 'V');
			}if($data_pilihan[3]==NULL) {
				$this->excel->getActiveSheet()->setCellValue('E14', ' ');
			} else {
				$this->excel->getActiveSheet()->setCellValue('E14', 'V');
			}if($data_pilihan[5]==NULL) {
				$this->excel->getActiveSheet()->setCellValue('E16', ' ');
			} else {
				$this->excel->getActiveSheet()->setCellValue('E16', 'V');
			}

			$this->excel->getActiveSheet()->getStyle('E12:E16')->getFont()->setBold(true);

			//$this->excel->getActiveSheet()->setCellValue('J30', '-'.$data_pilihan[0].'-'.$data_pilihan[1].'-'.$data_pilihan[2].'-'.$data_pilihan[3].'-'.$data_pilihan[4].'-'.$data_pilihan[5]);

			$this->excel->getActiveSheet()->getStyle('E12')->applyFromArray($styleArrayBorder);
			$this->excel->getActiveSheet()->getStyle('E14')->applyFromArray($styleArrayBorder);
			$this->excel->getActiveSheet()->getStyle('E16')->applyFromArray($styleArrayBorder);
			
			$this->excel->getActiveSheet()->getStyle('B12:B16')->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
			$this->excel->getActiveSheet()->getStyle('B12:B16')->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::VERTICAL_CENTER);

			$this->excel->getActiveSheet()->getStyle('E12:E16')->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
			$this->excel->getActiveSheet()->getStyle('E12:E16')->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::VERTICAL_CENTER);

			$this->excel->getActiveSheet()->setCellValue('A18', 'Silahkan sebutkan permohonan atau menjelaskan masalah yang terjadi : ');
			$this->excel->getActiveSheet()->getStyle('A18')->getFont()->setBold(true);

			$this->excel->getActiveSheet()->setCellValue('C20','- '.$rows2['permohonan_masalah']);
			$this->excel->getActiveSheet()->getStyle('C20:H20')->applyFromArray($styleArrayBorder);
			$this->excel->getActiveSheet()->mergeCells('C20:H20');

			$this->excel->getActiveSheet()->setCellValue('B22', 'Daftar barang (sesuai list penambahan) : ');
			$this->excel->getActiveSheet()->getStyle('B22')->getFont()->setBold(true);

			$this->excel->getActiveSheet()->getStyle('C24:H24')->getFill()->applyFromArray(array('type' => PHPExcel_Style_Fill::FILL_SOLID,'startcolor' => array('rgb' => 'B2B2B2')));
			$this->excel->getActiveSheet()->getStyle('C24:H24')->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
			
			$this->excel->getActiveSheet()->setCellValue('C24', 'ID DETAIL');
			$this->excel->getActiveSheet()->setCellValue('D24', 'ID BARANG');
			$this->excel->getActiveSheet()->setCellValue('E24', 'JUMLAH');
			$this->excel->getActiveSheet()->mergeCells('E24:F24');
			$this->excel->getActiveSheet()->setCellValue('G24', 'LOKASI');
			$this->excel->getActiveSheet()->setCellValue('H24', 'KETERANGAN');	

			$x = 24;

			for($i=0;$i<=$data_p1['totald']-1;$i++){
				$x++;
				$y= $x + 8;

			$rows3	=	$data_p1['rowsd'];
			$rows4	=	$rows3[$i];

				$this->excel->getActiveSheet()->setCellValue('C'.$x, $rows4['id_penambahan_dtl']);
				$this->excel->getActiveSheet()->setCellValue('D'.$x, $rows4['id_barang']);
				$this->excel->getActiveSheet()->setCellValue('E'.$x, $rows4['jumlah']);
				$this->excel->getActiveSheet()->mergeCells('E'.$x.':F'.$x);
				$this->excel->getActiveSheet()->setCellValue('G'.$x, $rows4['lokasi']);
				$this->excel->getActiveSheet()->setCellValue('H'.$x, $rows4['keterangan']);

			}
				$this->excel->getActiveSheet()->setCellValue('C'.$y, '(                                               )');
				$this->excel->getActiveSheet()->mergeCells('C'.$y.':D'.$y);
				$this->excel->getActiveSheet()->getStyle('C'.$y.':D'.$y)->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
				$this->excel->getActiveSheet()->setCellValue('G'.$y, '(                                               )');
				$this->excel->getActiveSheet()->mergeCells('G'.$y.':H'.$y);
				$this->excel->getActiveSheet()->getStyle('G'.$y.':H'.$y)->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_CENTER);



			$this->excel->getActiveSheet()->getStyle('C24:H'.$x)->applyFromArray($styleArrayBorder);
			// $this->excel->getActiveSheet()->getStyle('E45:I45')->applyFromArray($styleArrayUnderline);
			// $this->excel->getActiveSheet()->getStyle('E39:I46')->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_CENTER);

		}

		$this->excel->getActiveSheet()->getColumnDimension('A')->setWidth(3);
		$this->excel->getActiveSheet()->getColumnDimension('B')->setWidth(3);
		$this->excel->getActiveSheet()->getColumnDimension('C')->setWidth(17.60);
		$this->excel->getActiveSheet()->getColumnDimension('D')->setWidth(13);
		//$this->excel->getActiveSheet()->getRowDimension('17')->setRowHeight(80);
		$this->excel->getActiveSheet()->getColumnDimension('E')->setWidth(3);
		$this->excel->getActiveSheet()->getColumnDimension('F')->setWidth(8.43);
		$this->excel->getActiveSheet()->getColumnDimension('G')->setWidth(17);
		$this->excel->getActiveSheet()->getColumnDimension('H')->setWidth(18.80);
/*
		$this->excel->getActiveSheet()->getStyle('D1:C'.$this->excel->getActiveSheet()->getHighestRow())->getNumberFormat()->setFormatCode('#,##0.00'); 

		$this->excel->getActiveSheet()->getStyle('C1:C'.$this->excel->getActiveSheet()->getHighestRow())
    	->getAlignment()->setWrapText(true);
    	$this->excel->getActiveSheet()->getStyle('G1:G'.$this->excel->getActiveSheet()->getHighestRow())
    	->getAlignment()->setWrapText(true);*/

		//set aligment to center for that merged cell (A1 to D1)
		// $this->excel->getActiveSheet()->getStyle('B1:B2')->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
		//$this->excel->getActiveSheet()->getStyle('B4:B5')->getFont()->setBold(true);

		$filename= 'Laporan Penambahan_'.$rows2['nama'].'.xls'; //save our workbook as this file name
		header('Content-Type: application/vnd.ms-excel'); //mime type
		header('Content-Disposition: attachment;filename="'.$filename.'"'); //tell browser what's the file name
		header('Cache-Control: max-age=0'); //no cache
			             
		//save it to Excel5 format (excel 2003 .XLS file), change this to 'Excel2007' (and adjust the filename extension, also the header mime type)
		//if you want to save it as .XLSX Excel 2007 format
		$objWriter = PHPExcel_IOFactory::createWriter($this->excel, 'Excel5');  
		//force user to download the Excel file without writing it to server's HD
		$objWriter->save('php://output');
	}

	function konfirmasi_tagihan()
	{
		$data_tenant=get('data_tenant');
		$no_konfirmasi=get('no_konfirmasi');

		$data_explode1 = explode(',', $data_tenant);
		$x=0;

		$ls_sql	= " SELECT 		a.no_tagihan_sewa,a.nama_tenant,a.no_toko,
								a.jenis_usaha,a.lokasi_tempat,a.harga_sewa,
								a.tanggal_pembayaran,a.status_bayar,
								a.keterangan,TO_CHAR(a.tanggal_bayar,'DD/MM/YYYY') tanggal_bayar,
								a.no_bukti_pembayaran, b.nama_bulan, b.id_bulan,
								SUBSTR(a.tanggal_pembayaran, 4, INSTR(a.tanggal_pembayaran, '-')+2) AS tahun,
								SUBSTR(a.tanggal_pembayaran, 0, INSTR(a.tanggal_pembayaran, '-')-1) AS bulan,
								concat(b.nama_bulan,REPLACE(SUBSTR(a.tanggal_pembayaran, 4, INSTR(a.tanggal_pembayaran, '-')+2), '-',b.nama_bulan)) as periode_pembayaran
					FROM		pro_tagihan_sewa a
					LEFT JOIN 	pro_nama_bulan b ON a.id_bulan = b.id_bulan
					WHERE		lower(a.no_toko)='$data_explode1[0]' AND 
								a.status_bayar='Belum Bayar' AND
					 			a.lokasi_tempat LIKE '$data_explode1[1]%' AND
								(UPPER(a.no_tagihan_sewa) LIKE '%".strtoupper(post('keyword'))."%'
								OR UPPER(a.nama_tenant) LIKE '%".strtoupper(post('keyword'))."%'
								OR UPPER(a.no_toko) LIKE '%".strtoupper(post('keyword'))."%'
								OR UPPER(a.jenis_usaha) LIKE '%".strtoupper(post('keyword'))."%'
								OR UPPER(a.lokasi_tempat) LIKE '%".strtoupper(post('keyword'))."%'
								OR UPPER(a.harga_sewa) LIKE '%".strtoupper(post('keyword'))."%'
								OR UPPER(a.tanggal_pembayaran) LIKE '%".strtoupper(post('keyword'))."%'
								OR UPPER(a.status_bayar) LIKE '%".strtoupper(post('keyword'))."%')
								ORDER BY ".(post('sort')=='' ? 'a.no_tagihan_sewa' : post('sort'))." ".(post('order')=='' ? 'asc' : post('order'));	

		$ls_sql2	= "	SELECT 		COUNT(1)
					    FROM		pro_tagihan_sewa a
						LEFT JOIN 	pro_nama_bulan b ON a.id_bulan = b.id_bulan
						WHERE		lower(a.no_toko)='$data_explode1[0]' AND 
									a.status_bayar='Belum Bayar' AND
						 			a.lokasi_tempat LIKE '$data_explode1[1]%' AND
									(UPPER(a.no_tagihan_sewa) LIKE '%".strtoupper(post('keyword'))."%'
									OR UPPER(a.nama_tenant) LIKE '%".strtoupper(post('keyword'))."%'
									OR UPPER(a.no_toko) LIKE '%".strtoupper(post('keyword'))."%'
									OR UPPER(a.jenis_usaha) LIKE '%".strtoupper(post('keyword'))."%'
									OR UPPER(a.lokasi_tempat) LIKE '%".strtoupper(post('keyword'))."%'
									OR UPPER(a.harga_sewa) LIKE '%".strtoupper(post('keyword'))."%'
									OR UPPER(a.tanggal_pembayaran) LIKE '%".strtoupper(post('keyword'))."%'
									OR UPPER(a.status_bayar) LIKE '%".strtoupper(post('keyword'))."%')
									ORDER BY ".(post('sort')=='' ? 'a.no_tagihan_sewa' : post('sort'))." ".(post('order')=='' ? 'asc' : post('order'));	

		$total = $this->get_data($ls_sql2);

		$result = $this->db->query($ls_sql);

		$data_p = array(	'rows'=> $result->result_array(), 
								'total' => $total);

		$ls_sql3	= " SELECT		a.no_tagihan_listrik,a.nama_tenant,a.no_toko,
									a.jenis_usaha,a.tanggal,a.kwh_awal_meter,c.luas_tempat,
									a.kwh_akhir_meter,a.kwh_terpakai,a.tarif_per_kwh,
									a.jumlah_pemakaian,a.mcb,a.biaya_beban,a.jumlah_biaya_beban,
									a.total_tagihan,a.lokasi_tempat,a.no_bukti_pembayaran,
									TO_CHAR(a.tgl_bayar,'DD/MM/YYYY') tgl_bayar,
									a.status_bayar, b.nama_bulan, b.id_bulan,
									SUBSTR(a.tanggal, 4, INSTR(a.tanggal, '-')+2) AS tahun,
									SUBSTR(a.tanggal, 0, INSTR(a.tanggal, '-')-1) AS bulan,
									concat(b.nama_bulan,REPLACE(SUBSTR(a.tanggal, 4, INSTR(a.tanggal, '-')+2), '-',b.nama_bulan)) as periode_pembayaran
						FROM		pro_tagihan_listrik a
						LEFT JOIN  	pro_nama_bulan b ON a.id_bulan = b.id_bulan
						LEFT JOIN 	pro_sewa_gedung c ON a.no_toko = c.no_toko
						WHERE		lower(a.no_toko)='$data_explode1[0]' AND 
									a.status_bayar='Belum Bayar' AND
					 				a.lokasi_tempat LIKE '$data_explode1[1]%' AND
									(UPPER(a.no_tagihan_listrik) LIKE '%".strtoupper(post('keyword'))."%'
									OR UPPER(a.nama_tenant) LIKE '%".strtoupper(post('keyword'))."%'
									OR UPPER(a.no_toko) LIKE '%".strtoupper(post('keyword'))."%'
									OR UPPER(a.jenis_usaha) LIKE '%".strtoupper(post('keyword'))."%'
									OR UPPER(a.lokasi_tempat) LIKE '%".strtoupper(post('keyword'))."%'
									OR UPPER(a.tanggal) LIKE '%".strtoupper(post('keyword'))."%'
									OR UPPER(a.kwh_awal_meter) LIKE '%".strtoupper(post('keyword'))."%'
									OR UPPER(a.kwh_akhir_meter) LIKE '%".strtoupper(post('keyword'))."%'
									OR UPPER(a.kwh_terpakai) LIKE '%".strtoupper(post('keyword'))."%'
									OR UPPER(a.tarif_per_kwh) LIKE '%".strtoupper(post('keyword'))."%'
									OR UPPER(a.jumlah_pemakaian) LIKE '%".strtoupper(post('keyword'))."%'
									OR UPPER(a.mcb) LIKE '%".strtoupper(post('keyword'))."%'
									OR UPPER(a.biaya_beban) LIKE '%".strtoupper(post('keyword'))."%'
									OR UPPER(a.jumlah_biaya_beban) LIKE '%".strtoupper(post('keyword'))."%'
									OR UPPER(a.total_tagihan) LIKE '%".strtoupper(post('keyword'))."%') 
									ORDER BY ".(post('sort')=='' ? 'a.no_tagihan_listrik' : post('sort'))." ".(post('order')=='' ? 'asc' : post('order'));	
		
		$ls_sql4	= "	SELECT 		COUNT(1)
					    FROM		pro_tagihan_listrik a
						WHERE 		lower(a.no_toko)='$data_explode1[0]' AND 
									a.status_bayar='Belum Bayar' AND
						 			a.lokasi_tempat LIKE '$data_explode1[1]%' AND
									(UPPER(a.no_tagihan_listrik) LIKE '%".strtoupper(post('keyword'))."%'
									OR UPPER(a.nama_tenant) LIKE '%".strtoupper(post('keyword'))."%'
									OR UPPER(a.no_toko) LIKE '%".strtoupper(post('keyword'))."%'
									OR UPPER(a.jenis_usaha) LIKE '%".strtoupper(post('keyword'))."%'
									OR UPPER(a.lokasi_tempat) LIKE '%".strtoupper(post('keyword'))."%'
									OR UPPER(a.tanggal) LIKE '%".strtoupper(post('keyword'))."%'
									OR UPPER(a.kwh_awal_meter) LIKE '%".strtoupper(post('keyword'))."%'
									OR UPPER(a.kwh_akhir_meter) LIKE '%".strtoupper(post('keyword'))."%'
									OR UPPER(a.kwh_terpakai) LIKE '%".strtoupper(post('keyword'))."%'
									OR UPPER(a.tarif_per_kwh) LIKE '%".strtoupper(post('keyword'))."%'
									OR UPPER(a.jumlah_pemakaian) LIKE '%".strtoupper(post('keyword'))."%'
									OR UPPER(a.mcb) LIKE '%".strtoupper(post('keyword'))."%'
									OR UPPER(a.biaya_beban) LIKE '%".strtoupper(post('keyword'))."%'
									OR UPPER(a.jumlah_biaya_beban) LIKE '%".strtoupper(post('keyword'))."%'
									OR UPPER(a.total_tagihan) LIKE '%".strtoupper(post('keyword'))."%') 
									ORDER BY ".(post('sort')=='' ? 'a.no_tagihan_listrik' : post('sort'))." ".(post('order')=='' ? 'asc' : post('order'));	
			
		$totald = $this->get_data($ls_sql4);

		$resultd = $this->db->query($ls_sql3);

		$data_p1 = array(	'rowsd'=> $resultd->result_array(), 
								'totald' => $totald);


		$date = date('d M Y');

		//load our new PHPExcel library
		$this->load->library('excel');
		//activate worksheet number 1
		$this->excel->setActiveSheetIndex(0);
		//name the worksheet
		$this->excel->getActiveSheet()->setTitle("Laporan Konfirmasi Tagihan");

		$no = 1;

		/*$objDrawing = new PHPExcel_Worksheet_Drawing();
			$objDrawing->setName('Logo');
			$objDrawing->setDescription('Logo');
			$objDrawing->setPath('http://localhost/primkokas-new/files/logo_report.png');
			$objDrawing->setCoordinates('B1');
			$objDrawing->setHeight(36);*/
			
			/*$objPHPExcel = new PHPExcel();
			$sheet = $objPHPExcel->setSheetIndexAndTitle(1, "YOUR_SHEET_TITLE"); // first sheet
			$objDrawing = new PHPExcel_Worksheet_Drawing();
			$objDrawing->setName('Logo');
			$objDrawing->setDescription('Logo');
			$logo = base_path() . '/images/logo.png'; // Provide path to your logo file
			$objDrawing->setPath($logo);
			$objDrawing->setOffsetX(8);    // setOffsetX works properly
			$objDrawing->setOffsetY(300);  //setOffsetY has no effect
			$objDrawing->setCoordinates('B1');
			$objDrawing->setHeight(75); // logo height
			$objDrawing->setWorksheet($sheet);*/ 
			
        

		if ($data_p) {

			$styleArrayBorder = array(
				'borders' => array(
					'allborders' => array(
					'style' => PHPExcel_Style_Border::BORDER_THIN
					)
				)
			);

			$styleArrayUnderline = array(
			 'font' => array(
			 'underline' => PHPExcel_Style_Font::UNDERLINE_SINGLE,
			 'name' => 'Calibri',
			 'size' => 11,
			 'bold' => true
			 )
			);

			$styleArrayDefault = array(
			 'font' => array(
			 'name' => 'Calibri',
			 'size' => 11,
			 )
			);

			$styleArrayItalic = array(
			 'font' => array(
			 'name' => 'Calibri',
			 'size' => 11,
			 'italic' => true
			 )
			);

			$styleArrayFont = array(
			 'font' => array(
			 'name' => 'Calibri',
			 'size' => 9,
			 'color' => array('rgb' => 'FF4719'),
			 )
			);

			$styleArrayFont1 = array(
			 'font' => array(
			 'name' => 'Calibri',
			 'size' => 9,
			 'color' => array('rgb' => '1919FF'),
			 )
			);

			$rows = $data_p['rows'];
			$rows2 = $rows[0];
			

			$this->excel->getActiveSheet()->setCellValue('J1', 'PRIMER KOPERASI KARYAWAN KRAKATAU STEEL');
			$this->excel->getActiveSheet()->getStyle('J1')->applyFromArray($styleArrayFont);
			$this->excel->getActiveSheet()->getStyle('J1')->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_RIGHT);

			$this->excel->getActiveSheet()->setCellValue('J2', 'Gedung Krakatau Junction Lt. 3, Jl. KH. Yasin Neji Komp. PT KS');
			$this->excel->getActiveSheet()->setCellValue('J3', 'Cilegon - Banten 42435');
			$this->excel->getActiveSheet()->setCellValue('J4', 'Phone +62 (254) 392784, 372289 Fax. + (254) 372290, 398884');
			$this->excel->getActiveSheet()->setCellValue('J5', 'Website : www.primkokas.co.id');
			$this->excel->getActiveSheet()->setCellValue('J6', 'email: info@primkokas.co.id');
			$this->excel->getActiveSheet()->getStyle('J2:J6')->applyFromArray($styleArrayFont1);
			$this->excel->getActiveSheet()->getStyle('J2:J6')->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_RIGHT);

			$this->excel->getActiveSheet()->setCellValue('A8', 'Nomor');
			$this->excel->getActiveSheet()->setCellValue('A9', 'Lampiran');
			$this->excel->getActiveSheet()->setCellValue('A10', 'Perihal');
			$this->excel->getActiveSheet()->getStyle('A10')->getFont()->setBold(true);

			$this->excel->getActiveSheet()->setCellValue('B8', ':' );
			$this->excel->getActiveSheet()->setCellValue('C8', $no_konfirmasi);
			$this->excel->getActiveSheet()->setCellValue('C9', '1 (satu) set.');
			$this->excel->getActiveSheet()->setCellValue('C10', 'Konfirmasi Tagihan');

			$this->excel->getActiveSheet()->getStyle('C10')->applyFromArray($styleArrayUnderline);
			$this->excel->getActiveSheet()->setCellValue('C12', 'Kepada Yth.');
			$this->excel->getActiveSheet()->setCellValue('C13', 'Bapak/Ibu '.$rows2['nama_tenant']);
			$this->excel->getActiveSheet()->getStyle('C13')->getFont()->setBold(true);

			$this->excel->getActiveSheet()->setCellValue('C14',  $rows2['lokasi_tempat'].'No. '.$rows2['no_toko']);
			$this->excel->getActiveSheet()->setCellValue('C15', 'Di');
			$this->excel->getActiveSheet()->setCellValue('D16', 'Tempat');
			$this->excel->getActiveSheet()->setCellValue('C18', 'Dengan Hormat');

			$this->excel->getActiveSheet()->setCellValue('C20', 'Puji syukur ke hadirat Allah SWT teriring doa semoga Bapak/Ibu dalam keadaan ');
			$this->excel->getActiveSheet()->setCellValue('C21', 'sehat wal afiat dan senantiasa mendapat lindungan-Nya di dalam menjalankan');
			$this->excel->getActiveSheet()->setCellValue('C22', 'tugas sehari-hari. Amin.');

			$this->excel->getActiveSheet()->setCellValue('C24', 'Bersama ini kami selaku Pihak Property Management ingin menyampaikan');
			$this->excel->getActiveSheet()->setCellValue('C25', 'informasi bahwa Bapak/Ibu ' .$rows2['nama_tenant']. ' belum menyelesaikan tagihan sewa');
			$this->excel->getActiveSheet()->setCellValue('C26', 'toko NO. '.$rows2['no_toko']. ' untuk periode yang sudah tertera, yaitu sebagai berikut:');

			$this->excel->getActiveSheet()->setCellValue('C28', '1.');
			$this->excel->getActiveSheet()->setCellValue('D28', 'Tagihan Sewa');
			$this->excel->getActiveSheet()->getStyle('C28:D28')->getFont()->setBold(true);

			$x=28;

			for($i=0;$i<=$data_p['total']-1;$i++){
				$x++;

				//Cell Looping tagihan
				$y=$x + 2;

				$rows = $data_p['rows'];
				$rows2 = $rows[$i];


			$this->excel->getActiveSheet()->setCellValue('C'.$x, '-');
			$this->excel->getActiveSheet()->setCellValue('D'.$x, 'Periode ' .$rows2['periode_pembayaran']);
			$this->excel->getActiveSheet()->setCellValue('H'.$x,  $rows2['harga_sewa']);
			$this->excel->getActiveSheet()->setCellValue('G'.$x, '@');
			$this->excel->getActiveSheet()->getStyle('H'.$x)->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_LEFT);
			$this->excel->getActiveSheet()->getStyle('G'.$x)->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_RIGHT);
			$this->excel->getActiveSheet()->getStyle('H'.$x)->getNumberFormat()->setFormatCode('Rp #,##0'); 
			$this->excel->getActiveSheet()->getStyle('H'.$x)->getNumberFormat()->setFormatCode('Rp #,##0');

			}

			$query = $this->db->query("SELECT SUM(harga_sewa) as harga_sewa FROM pro_tagihan_sewa WHERE no_toko = '$data_explode1[0]' AND lokasi_tempat = '$data_explode1[1]' AND status_bayar = 'Belum Bayar'");
			$total_sum_S = $query->row_array();

			for($ia=0;$ia<=$data_p1['totald']-1;$ia++){
				$y++;
				
				//Cell Looping tagihan
				$z=$y - 1;
				/*$za= $z + 2;
				$zb= $za + 1;
				//Cell Penutup
				$zc= $zb + 2; $zd= $zc + 1;
				$ze= $zd + 2; $zf= $ze + 1;
				//Cell Ttd
				$zg= $zf + 2;
				$zh= $zg + 1;
				$zi= $zh + 1;
				$zj= $zi + 5;
				$zk= $zj + 1;
				//Cell arsip
				$zl= $zk + 2;
				$zm= $zl + 1;
				$zn= $zm + 1;*/
				

				$rows3 = $data_p1['rowsd'];
				$rows4 = $rows3[$ia];


			$this->excel->getActiveSheet()->setCellValue('D'.$z, 'Tagihan Listrik');
			$this->excel->getActiveSheet()->getStyle('C'.$z.':D'.$z)->getFont()->setBold(true);
			$this->excel->getActiveSheet()->setCellValue('C'.$y, '-');
			$this->excel->getActiveSheet()->setCellValue('D'.$y, 'Periode ' .$rows4['periode_pembayaran']);
			$this->excel->getActiveSheet()->setCellValue('H'.$y,  $rows4['total_tagihan']);
			$this->excel->getActiveSheet()->setCellValue('G'.$y, '@');
			$this->excel->getActiveSheet()->getStyle('H'.$y)->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_LEFT);
			$this->excel->getActiveSheet()->getStyle('G'.$y)->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_RIGHT);
			$this->excel->getActiveSheet()->getStyle('H'.$y)->getNumberFormat()->setFormatCode('Rp #,##0'); 
			$this->excel->getActiveSheet()->getStyle('H'.$y)->getNumberFormat()->setFormatCode('Rp #,##0');

			}

			$query = $this->db->query("SELECT SUM(total_tagihan) as total_tagihan FROM pro_tagihan_listrik WHERE no_toko = '$data_explode1[0]' AND lokasi_tempat ='$data_explode1[1]' AND status_bayar='Belum Bayar' ");
			$total_sum_L = $query->row_array();

			//Cell Looping tagihan
				$z=$y - 1;
				$za= $z + 2;
				$zb= $za + 1;
				//Cell Penutup
				$zc= $zb + 2; $zd= $zc + 1;
				$ze= $zd + 2; $zf= $ze + 1;
				//Cell Ttd
				$zg= $zf + 2;
				$zh= $zg + 1;
				$zi= $zh + 1;
				$zj= $zi + 5;
				$zk= $zj + 1;
				//Cell arsip
				$zl= $zk + 2;
				$zm= $zl + 1;
				$zn= $zm + 1;

			$grand_total = intval($total_sum_S['harga_sewa']) + intval($total_sum_L['total_tagihan']); 
			$tes= $this->toTerbilang(intval($grand_total));
			//echo(intval($total_sum_S['harga_sewa']));

			$this->excel->getActiveSheet()->setCellValue('C'.$za, 'Total Keseluruhan yang harus di bayar');
			$this->excel->getActiveSheet()->setCellValue('G'.$za, '@');
			$this->excel->getActiveSheet()->setCellValue('H'.$za, $grand_total);
			$this->excel->getActiveSheet()->getStyle('C'.$za.':H'.$za)->getFont()->setBold(true);
			$this->excel->getActiveSheet()->getStyle('H'.$za)->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_LEFT);
			$this->excel->getActiveSheet()->getStyle('G'.$za)->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_RIGHT);
			$this->excel->getActiveSheet()->setCellValue('C'.$zb, "( ".$tes." Rupiah )");
			$this->excel->getActiveSheet()->getStyle('C'.$zb)->applyFromArray($styleArrayItalic);
			$this->excel->getActiveSheet()->getStyle('H'.$za)->getNumberFormat()->setFormatCode('Rp #,##0'); 
			$this->excel->getActiveSheet()->getStyle('H'.$zb)->getNumberFormat()->setFormatCode('Rp #,##0'); 

			$this->excel->getActiveSheet()->setCellValue('C'.$zc, 'Kami harapkan Bapak/Ibu dapat segera menyelesaikan tagihan tersebut sesuai ');
			$this->excel->getActiveSheet()->setCellValue('C'.$zd, 'syarat dan ketentuan yang berlaku.');
			$this->excel->getActiveSheet()->setCellValue('C'.$ze, 'Demikian pemberitahuan ini kami sampaikan, atas perhatian dan kerjasamanya');
			$this->excel->getActiveSheet()->setCellValue('C'.$zf, 'diucapkan terima kasih.');

			$this->excel->getActiveSheet()->setCellValue('E'.$zh, 'Mengetahui,');
			$this->excel->getActiveSheet()->setCellValue('E'.$zj, 'Aan Supriana');
			$this->excel->getActiveSheet()->setCellValue('E'.$zk, 'Internal Busines & Property Div. Manager');

			$this->excel->getActiveSheet()->setCellValue('H'.$zg, 'Cilegon, '.$date);
			$this->excel->getActiveSheet()->setCellValue('H'.$zh, 'PRIMER KOPERASI KARYAWAN');
			$this->excel->getActiveSheet()->setCellValue('H'.$zi, 'KRAKATAU STEEL');
			$this->excel->getActiveSheet()->getStyle('H'.$zh.':H'.$zi)->getFont()->setBold(true);

			$this->excel->getActiveSheet()->setCellValue('H'.$zj, 'Ngajito');
			$this->excel->getActiveSheet()->setCellValue('H'.$zk, 'Property Div.');

			$this->excel->getActiveSheet()->setCellValue('C'.$zl, 'Tembusan :');
			$this->excel->getActiveSheet()->setCellValue('D'.$zm, '1. Yth. Ketua Umun PRIMKOKAS');
			$this->excel->getActiveSheet()->setCellValue('D'.$zn, '2. Arsip');

			$this->excel->getActiveSheet()->getStyle('E'.$zj.':I'.$zj)->applyFromArray($styleArrayUnderline);
			$this->excel->getActiveSheet()->getStyle('E'.$zg.':I'.$zk)->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_CENTER);

		}

		$this->excel->getActiveSheet()->getColumnDimension('A')->setWidth(8.4);
		$this->excel->getActiveSheet()->getColumnDimension('B')->setWidth(0.7);
		$this->excel->getActiveSheet()->getColumnDimension('C')->setWidth(1.3);
		$this->excel->getActiveSheet()->getColumnDimension('D')->setWidth(8.5);
		$this->excel->getActiveSheet()->getColumnDimension('E')->setWidth(15.5);
		$this->excel->getActiveSheet()->getColumnDimension('F')->setWidth(9.4);
		$this->excel->getActiveSheet()->getColumnDimension('G')->setWidth(12);
		$this->excel->getActiveSheet()->getColumnDimension('I')->setWidth(1);
		$this->excel->getActiveSheet()->getColumnDimension('H')->setWidth(18);
		$this->excel->getActiveSheet()->getRowDimension('7')->setRowHeight(3);
		/*$this->excel->getActiveSheet()->getRowDimension('30')->setRowHeight(3);
		$this->excel->getActiveSheet()->getRowDimension('33')->setRowHeight(3);
		$this->excel->getActiveSheet()->getRowDimension('38')->setRowHeight(3);*/

/*
		$this->excel->getActiveSheet()->getStyle('D1:C'.$this->excel->getActiveSheet()->getHighestRow())->getNumberFormat()->setFormatCode('#,##0.00'); 

		$this->excel->getActiveSheet()->getStyle('C1:C'.$this->excel->getActiveSheet()->getHighestRow())
    	->getAlignment()->setWrapText(true);
    	$this->excel->getActiveSheet()->getStyle('G1:G'.$this->excel->getActiveSheet()->getHighestRow())
    	->getAlignment()->setWrapText(true);*/

		//set aligment to center for that merged cell (A1 to D1)
		// $this->excel->getActiveSheet()->getStyle('B1:B2')->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
		//$this->excel->getActiveSheet()->getStyle('B4:B5')->getFont()->setBold(true);

		$filename= 'Laporan Konformasi Tagihan_'.$rows2['no_tagihan_sewa'].'.xls'; //save our workbook as this file name
		header('Content-Type: application/vnd.ms-excel'); //mime type
		header('Content-Disposition: attachment;filename="'.$filename.'"'); //tell browser what's the file name
		header('Cache-Control: max-age=0'); //no cache
			             
		//save it to Excel5 format (excel 2003 .XLS file), change this to 'Excel2007' (and adjust the filename extension, also the header mime type)
		//if you want to save it as .XLSX Excel 2007 format
		$objWriter = PHPExcel_IOFactory::createWriter($this->excel, 'Excel5');  
		//force user to download the Excel file without writing it to server's HD
		$objWriter->save('php://output');
	
	}

		function tagihan_telephone()
	{
		$id_tagihan=get('id_tagihan');
		$x=0;

		$ls_sql	= " SELECT		no_tagihan_tlp,id_tagihan_tlp,
								TO_CHAR(tanggal_bayar,'DD/MM/YYYY') tanggal_bayar,
								nama_tenant,atas_nama,periode_pembayaran,alamat
					FROM		pro_tagihan_telephone 
					WHERE	id_tagihan_tlp = ".$id_tagihan."
							ORDER BY ".(post('sort')=='' ? 'id_tagihan_tlp' : post('sort'))." ".(post('order')=='' ? 'asc' : post('order'));	
			
		$ls_sql2	= "	SELECT 	COUNT(1)
					  	FROM	pro_tagihan_telephone
						WHERE	id_tagihan_tlp = ".$id_tagihan."
								ORDER BY ".(post('sort')=='' ? 'id_tagihan_tlp' : post('sort'))." ".(post('order')=='' ? 'asc' : post('order'));	
		
		$total = $this->get_data($ls_sql2);

		$result = $this->db->query($ls_sql);

		$data_p = array(	'rows'=> $result->result_array(), 
								'total' => $total);

		$ls_sql3	= " SELECT	id_tagihan_tlp,id_tagihan_tlp_dtl,
								biaya_tagihan,biaya_adm_bank,
								keterangan_tagihan
						FROM	pro_tagihan_telephone_dtl
						WHERE	id_tagihan_tlp = ".$id_tagihan."
								ORDER BY ".(post('sort')=='' ? 'id_tagihan_tlp_dtl' : post('sort'))." ".(post('order')=='' ? 'asc' : post('order'));	
			
		$ls_sql4	= "	SELECT 	COUNT(1)
					  	FROM	pro_tagihan_telephone_dtl
						WHERE	id_tagihan_tlp = ".$id_tagihan."
								ORDER BY ".(post('sort')=='' ? 'id_tagihan_tlp_dtl' : post('sort'))." ".(post('order')=='' ? 'asc' : post('order'));	
		
		$totald = $this->get_data($ls_sql4);

		$resultd = $this->db->query($ls_sql3);

		$data_p1 = array(	'rowsd'=> $resultd->result_array(), 
								'totald' => $totald);

		$date = date('d M Y');

		//load our new PHPExcel library
		$this->load->library('excel');
		//activate worksheet number 1
		$this->excel->setActiveSheetIndex(0);
		//name the worksheet
		$this->excel->getActiveSheet()->setTitle("Laporan Tagihan Telephone");

		$no = 1;

		/*$objDrawing = new PHPExcel_Worksheet_Drawing();
			$objDrawing->setName('Logo');
			$objDrawing->setDescription('Logo');
			$objDrawing->setPath('http://localhost/primkokas-new/files/logo_report.png');
			$objDrawing->setCoordinates('B1');
			$objDrawing->setHeight(36);*/
			
			/*$objPHPExcel = new PHPExcel();
			$sheet = $objPHPExcel->setSheetIndexAndTitle(1, "YOUR_SHEET_TITLE"); // first sheet
			$objDrawing = new PHPExcel_Worksheet_Drawing();
			$objDrawing->setName('Logo');
			$objDrawing->setDescription('Logo');
			$logo = base_path() . '/images/logo.png'; // Provide path to your logo file
			$objDrawing->setPath($logo);
			$objDrawing->setOffsetX(8);    // setOffsetX works properly
			$objDrawing->setOffsetY(300);  //setOffsetY has no effect
			$objDrawing->setCoordinates('B1');
			$objDrawing->setHeight(75); // logo height
			$objDrawing->setWorksheet($sheet);*/ 
			
        

		if ($data_p) {

			$styleArrayBorder = array(
				'borders' => array(
					'allborders' => array(
					'style' => PHPExcel_Style_Border::BORDER_THIN
					)
				)
			);

			$styleArrayUnderline = array(
			 'font' => array(
			 'underline' => PHPExcel_Style_Font::UNDERLINE_SINGLE,
			 'name' => 'Calibri',
			 'size' => 11,
			 'bold' => true
			 )
			);

			$styleArrayDefault = array(
			 'font' => array(
			 'name' => 'Calibri',
			 'size' => 11,
			 )
			);

			$styleArrayItalic = array(
			 'font' => array(
			 'underline' => PHPExcel_Style_Font::UNDERLINE_SINGLE,
			 'name' => 'Calibri',
			 'size' => 11,
			 'bold' => true,
			 'italic' => true
			 )
			);

			$styleArrayFont = array(
			 'font' => array(
			 'name' => 'Calibri',
			 'size' => 9,
			 'color' => array('rgb' => 'FF4719'),
			 )
			);

			$styleArrayFont1 = array(
			 'font' => array(
			 'name' => 'Calibri',
			 'size' => 9,
			 'color' => array('rgb' => '1919FF'),
			 )
			);


			$rows = $data_p['rows'];
			$rows2 = $rows[0];

			//var_dump($rows2['tanggal_bayar']);

			$bulan_periode = explode("/", $rows2['tanggal_bayar']);
			    if($bulan_periode[0]<='09'){
			      $y1 = substr($bulan_periode[0], 1, 1);

			      $hasil1 = "";
			      $iromawi1 =
			      array("","Januari","Februari","Maret","April","Mei","Juni","Juli","Agustus","September");
			      if(array_key_exists($y1,$iromawi1)){
			        $hasil1 = $iromawi1[$y1];
			      }

			      $tgl_new1 = $hasil1." - ".$bulan_periode[2];

			    } else {

			      $hasil1 = "";
			      $iromawi1 =
			      array("","","","","","","","","","","Oktober","November","Desember");
			      if(array_key_exists($bulan_periode[0],$iromawi1)){
			        $hasil1 = $iromawi1[$bulan_periode[0]];
			      }
			      $tgl_new1 = $hasil1." - ".$bulan_periode[2];
			    }

			//var_dump($tgl_new1);

			$this->excel->getActiveSheet()->setCellValue('A2', 'Nomor');
			$this->excel->getActiveSheet()->setCellValue('A3', 'Lampiran');
			$this->excel->getActiveSheet()->setCellValue('A4', 'Perihal');
			$this->excel->getActiveSheet()->getStyle('A4')->getFont()->setBold(true);

			$this->excel->getActiveSheet()->setCellValue('B2', ':' );
			$this->excel->getActiveSheet()->setCellValue('C2', $rows2['no_tagihan_tlp']);
			$this->excel->getActiveSheet()->setCellValue('C3', '1 (satu) set.');
			$this->excel->getActiveSheet()->setCellValue('C4', 'Pemakaian Telephone Bulan '.$tgl_new1);

			$this->excel->getActiveSheet()->getStyle('C4')->applyFromArray($styleArrayUnderline);
			$this->excel->getActiveSheet()->setCellValue('C7', 'Kepada Yth.');
			$this->excel->getActiveSheet()->setCellValue('C8', $rows2['nama_tenant']);
			$this->excel->getActiveSheet()->getStyle('C8')->getFont()->setBold(true);

			$this->excel->getActiveSheet()->setCellValue('C9',  $rows2['alamat']);
			$this->excel->getActiveSheet()->setCellValue('C11', 'Up. ');
			$this->excel->getActiveSheet()->setCellValue('D11', ': '.$rows2['atas_nama']);
			$this->excel->getActiveSheet()->getStyle('D11')->applyFromArray($styleArrayItalic);
			$this->excel->getActiveSheet()->setCellValue('C13', 'Dengan Hormat,');
			$this->excel->getActiveSheet()->setCellValue('C15', 'Puji syukur ke hadirat Tuhan Yang Maha Esa, teriring doa semoga Bapak dalam');
			$this->excel->getActiveSheet()->setCellValue('C16', 'keadaan sehat wal’afiat dan senantiasa mendapat  lindungan-Nya di dalam ');
			$this->excel->getActiveSheet()->setCellValue('C17', 'menjalankan tugas sehari-hari. Amin.');

			$this->excel->getActiveSheet()->setCellValue('C19', 'Berikut ini disampaikan biaya pemakaian Telephone periode '.$tgl_new1.', dan ');
			$this->excel->getActiveSheet()->setCellValue('C20', 'rekening koran (terlampir) :');

			$x=21;
			$no=0;

			for($i=0;$i<=$data_p1['totald']-1;$i++){
				$x++;
				$no++;

				//Cell Looping tagihan
				$y=$x + 1;

				$yv=$y + 2;
				$yx=$yv + 2;
				$yb=$yx + 1;
				$yc=$yb + 1;

				$ya=$yc + 2;
				$ys=$ya + 1;
				$yd=$ys + 1;

				$yq=$yd + 5;
				$yw=$yq + 1;

				$ye=$yw + 2;
				$yr=$ye + 1;
				$yt=$yr + 1;
				$yp=$yt + 1;

				$rows3 = $data_p1['rowsd'];
				$rows4 = $rows3[$i];

			$query = $this->db->query("SELECT SUM(biaya_tagihan) as biaya_tagihan FROM pro_tagihan_telephone_dtl WHERE id_tagihan_tlp = '$id_tagihan' ");
			$total_sum_t = $query->row_array();

			$query1 = $this->db->query("SELECT SUM(biaya_adm_bank) as biaya_adm_bank FROM pro_tagihan_telephone_dtl WHERE id_tagihan_tlp = '$id_tagihan' ");
			$total_sum_b = $query1->row_array();

			$total_bayar = intval($total_sum_t['biaya_tagihan']) + intval($total_sum_b['biaya_adm_bank']);

			if($x%2==0){
				$this->excel->getActiveSheet()->setCellValue('C'.$x, $no);
				$this->excel->getActiveSheet()->getStyle('G'.$x)->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_RIGHT);
				$this->excel->getActiveSheet()->setCellValue('D'.$x, 'Biaya pemakaian Telp : ');
				$this->excel->getActiveSheet()->setCellValue('F'.$x, $rows4['keterangan_tagihan']);
				$this->excel->getActiveSheet()->getStyle('F'.$x)->getNumberFormat()->setFormatCode(PHPExcel_Style_NumberFormat::FORMAT_TEXT);
				$this->excel->getActiveSheet()->setCellValue('H'.$x, $rows4['biaya_tagihan']);
				$this->excel->getActiveSheet()->setCellValue('I'.$x, ',-');
				$this->excel->getActiveSheet()->setCellValue('D'.$y, 'Biaya Adm. Bank');
				$this->excel->getActiveSheet()->setCellValue('H'.$y, $rows4['biaya_adm_bank']);
				$this->excel->getActiveSheet()->setCellValue('I'.$y, ',-');
				$this->excel->getActiveSheet()->getStyle('H'.$x)->getNumberFormat()->setFormatCode('Rp #,##0'); 
				$this->excel->getActiveSheet()->getStyle('H'.$y)->getNumberFormat()->setFormatCode('Rp #,##0');

			} if($y%2==1){
				$x++;
				$y=$x + 1;
				$this->excel->getActiveSheet()->getStyle('H'.$x)->getNumberFormat()->setFormatCode('Rp #,##0'); 
				$this->excel->getActiveSheet()->getStyle('H'.$y)->getNumberFormat()->setFormatCode('Rp #,##0');
				/*$this->excel->getActiveSheet()->setCellValue('C'.$x, $no);
				$this->excel->getActiveSheet()->getStyle('G'.$x)->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_RIGHT);
				$this->excel->getActiveSheet()->setCellValue('D'.$x, 'Biaya pemakaian Telp : '.$x);
				$this->excel->getActiveSheet()->setCellValue('F'.$x, $rows4['keterangan_tagihan']);
				$this->excel->getActiveSheet()->setCellValue('H'.$x, $rows4['biaya_tagihan']);*/
				/*$this->excel->getActiveSheet()->setCellValue('D'.$y, 'Biaya Adm. Bank'.$y);
				$this->excel->getActiveSheet()->setCellValue('H'.$y, $rows4['biaya_adm_bank']);*/
			}
			//$this->excel->getActiveSheet()->getStyle('G'.$x)->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_RIGHT);
			//$this->excel->getActiveSheet()->getStyle('G'.$y)->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_RIGHT);
			$this->excel->getActiveSheet()->getStyle('H'.$x)->getNumberFormat()->setFormatCode('Rp #,##0'); 
			$this->excel->getActiveSheet()->getStyle('H'.$y)->getNumberFormat()->setFormatCode('Rp #,##0');

			}

			
			$this->excel->getActiveSheet()->setCellValue('C'.$yv, 'Total Pemakaian ');
			$this->excel->getActiveSheet()->setCellValue('H'.$yv, $total_bayar);
			$this->excel->getActiveSheet()->getStyle('H'.$yv)->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_RIGHT);
			$this->excel->getActiveSheet()->setCellValue('I'.$yv, ',-');
			$this->excel->getActiveSheet()->getStyle('H'.$yv.':I'.$yv)->getFont()->setBold(true);
			$this->excel->getActiveSheet()->getStyle('I'.$yv)->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_LEFT);
			$this->excel->getActiveSheet()->getStyle('H'.$yv)->getNumberFormat()->setFormatCode('Rp #,##0');
			$this->excel->getActiveSheet()->setCellValue('C'.$yx, 'Pembayaran dapat dilakukan transfer via rekening No. 155-00-0259247-8 a/n');
			$this->excel->getActiveSheet()->setCellValue('C'.$yb, 'PRIMKOKAS – PROPERTY Bank Mandiri Cab. Cilegon-Anyer.');
			$this->excel->getActiveSheet()->setCellValue('C'.$yc, 'Demikian ini kami sampaikan atas perhatian dan kerjasamanya diucapkan terimakasih.');

			$this->excel->getActiveSheet()->setCellValue('E'.$ya, 'Mengetahui,');
			$this->excel->getActiveSheet()->setCellValue('E'.$yq, 'Aan Supriana');
			$this->excel->getActiveSheet()->setCellValue('E'.$yw, 'Internal Busines & Property Div. Manager');

			$this->excel->getActiveSheet()->setCellValue('H'.$ya, 'Cilegon, '.$date);
			$this->excel->getActiveSheet()->setCellValue('H'.$ys, 'PRIMER KOPERASI KARYAWAN');
			$this->excel->getActiveSheet()->setCellValue('H'.$yd, 'KRAKATAU STEEL');
			$this->excel->getActiveSheet()->getStyle('H'.$ys.':H'.$yd)->getFont()->setBold(true);

			$this->excel->getActiveSheet()->setCellValue('H'.$yq, 'Ngajito');
			$this->excel->getActiveSheet()->setCellValue('H'.$yw, 'Property Div.');

			$this->excel->getActiveSheet()->setCellValue('C'.$ye, 'Tembusan :');
			$this->excel->getActiveSheet()->setCellValue('D'.$yr, '1. Yth. Ketua Umum PRIMKOKAS ');
			$this->excel->getActiveSheet()->setCellValue('D'.$yt, '2. Yth. IB & Property Div. Mgr');
			$this->excel->getActiveSheet()->setCellValue('D'.$yp, '2. Arsip');

			$this->excel->getActiveSheet()->getStyle('E'.$yq.':I'.$yq)->applyFromArray($styleArrayUnderline);
			$this->excel->getActiveSheet()->getStyle('E'.$ya.':I'.$yw)->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_CENTER);

		}

		$this->excel->getActiveSheet()->getColumnDimension('A')->setWidth(8.4);
		$this->excel->getActiveSheet()->getColumnDimension('B')->setWidth(0.7);
		$this->excel->getActiveSheet()->getColumnDimension('C')->setWidth(4);
		$this->excel->getActiveSheet()->getColumnDimension('D')->setWidth(8.5);
		$this->excel->getActiveSheet()->getColumnDimension('E')->setWidth(15.5);
		$this->excel->getActiveSheet()->getColumnDimension('F')->setWidth(23.57);
		$this->excel->getActiveSheet()->getColumnDimension('G')->setWidth(0.5);
		$this->excel->getActiveSheet()->getColumnDimension('I')->setWidth(3);
		$this->excel->getActiveSheet()->getColumnDimension('H')->setWidth(18);
		$this->excel->getActiveSheet()->getRowDimension('7')->setRowHeight(3);
		/*$this->excel->getActiveSheet()->getRowDimension('30')->setRowHeight(3);
		$this->excel->getActiveSheet()->getRowDimension('33')->setRowHeight(3);
		$this->excel->getActiveSheet()->getRowDimension('38')->setRowHeight(3);*/

/*
		$this->excel->getActiveSheet()->getStyle('D1:C'.$this->excel->getActiveSheet()->getHighestRow())->getNumberFormat()->setFormatCode('#,##0.00'); 

		$this->excel->getActiveSheet()->getStyle('C1:C'.$this->excel->getActiveSheet()->getHighestRow())
    	->getAlignment()->setWrapText(true);
    	$this->excel->getActiveSheet()->getStyle('G1:G'.$this->excel->getActiveSheet()->getHighestRow())
    	->getAlignment()->setWrapText(true);*/

		//set aligment to center for that merged cell (A1 to D1)
		// $this->excel->getActiveSheet()->getStyle('B1:B2')->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
		//$this->excel->getActiveSheet()->getStyle('B4:B5')->getFont()->setBold(true);

		$filename= 'Laporan tagihan_telephone_'.$rows2['nama_tenant'].'.xls'; //save our workbook as this file name
		header('Content-Type: application/vnd.ms-excel'); //mime type
		header('Content-Disposition: attachment;filename="'.$filename.'"'); //tell browser what's the file name
		header('Cache-Control: max-age=0'); //no cache
			             
		//save it to Excel5 format (excel 2003 .XLS file), change this to 'Excel2007' (and adjust the filename extension, also the header mime type)
		//if you want to save it as .XLSX Excel 2007 format
		$objWriter = PHPExcel_IOFactory::createWriter($this->excel, 'Excel5');  
		//force user to download the Excel file without writing it to server's HD
		$objWriter->save('php://output');
	
	}

	function kontrol_sertifikasi_peralatan()
	{
		
		$x=0;

		$ls_sql	= " SELECT	*
					FROM	pro_kontrol_sertifikasi
					WHERE   (UPPER(kode_alat) LIKE '%".strtoupper(post('keyword'))."%'
							OR UPPER(nama_peralatan) LIKE '%".strtoupper(post('keyword'))."%') 
							ORDER BY ".(post('sort')=='' ? 'kode_alat' : post('sort'))." ".(post('order')=='' ? 'asc' : post('order'));	
	
		$ls_sql2	= "	SELECT COUNT(1)
					FROM	pro_kontrol_sertifikasi
					WHERE   (UPPER(kode_alat) LIKE '%".strtoupper(post('keyword'))."%'
							OR UPPER(nama_peralatan) LIKE '%".strtoupper(post('keyword'))."%') 
							ORDER BY ".(post('sort')=='' ? 'kode_alat' : post('sort'))." ".(post('order')=='' ? 'asc' : post('order'));	
	
		$total = $this->get_data($ls_sql2);

		$result = $this->db->query($ls_sql);

		$data_p = array(	'rows'=> $result->result_array(), 
								'total' => $total);

		$date = date('Y-m-d');

		//load our new PHPExcel library
		$this->load->library('excel');
		//activate worksheet number 1
		$this->excel->setActiveSheetIndex(0);
		//name the worksheet
		$this->excel->getActiveSheet()->setTitle("Kontrol Sertifikasi");

		$no = 1;

			
		if ($data_p) {

			$styleArrayBorder = array(
				'borders' => array(
					'allborders' => array(
					'style' => PHPExcel_Style_Border::BORDER_THIN
					)
				)
			);

			$this->excel->getActiveSheet()->setCellValue('B8', 'KODE ALAT');
			$this->excel->getActiveSheet()->setCellValue('C8', 'NAMA PERALATAN');
			$this->excel->getActiveSheet()->setCellValue('D8', 'NOMOR SERTIFIKASI');
			$this->excel->getActiveSheet()->setCellValue('E8', 'TANGGALBERLAKU AWAL');
			$this->excel->getActiveSheet()->setCellValue('F8', 'TANGGALBERLAKU AKHIR');

			$this->excel->getActiveSheet()->getStyle('B8:F8')->getFont()->setBold(true);
			$this->excel->getActiveSheet()->getStyle('B8:F8')->getFill()->applyFromArray(array('type' => PHPExcel_Style_Fill::FILL_SOLID,'startcolor' => array('rgb' => 'EEEE11')));
			$this->excel->getActiveSheet()->getStyle('B8:F8')->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_CENTER);

			$x = 8;

			for($i=0;$i<=$data_p['total']-1;$i++){
				$x++;

				$rows = $data_p['rows'];
				$rows2 = $rows[$i];

				$this->excel->getActiveSheet()->setCellValue('B'.$x, $rows2['kode_alat']);
				$this->excel->getActiveSheet()->getStyle('B'.$x)->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
				$this->excel->getActiveSheet()->setCellValue('C'.$x, $rows2['nama_peralatan']);
				$this->excel->getActiveSheet()->setCellValue('D'.$x, $rows2['nomor_sertifikasi']);
				$this->excel->getActiveSheet()->setCellValueExplicit('F'.$x, $rows2['nomor_sertifikasi'], PHPExcel_Cell_DataType::TYPE_STRING);
				$this->excel->getActiveSheet()->setCellValue('E'.$x, $rows2['tgl_berlaku_awal']);
				$this->excel->getActiveSheet()->setCellValue('F'.$x, $rows2['tgl_berlaku_akhir']);

				

			}
		}

		$this->excel->getActiveSheet()->setCellValue('B4', strtoupper("Kontrol Sertifikasi Peralatan"));
		$this->excel->getActiveSheet()->setCellValue('B5', '('.$date.')');			

		$styleArray = array(
			'borders' => array(
			    'allborders' => array(
			    'style' => PHPExcel_Style_Border::BORDER_THIN
			    )
			),
			'font'  => array(
			    'size'  => 9,
			    'name'  => 'verdana'
			)
		);

		$this->excel->getActiveSheet()->getStyle('B8:F'.$x)->applyFromArray($styleArray);
		unset($styleArray);

		$styleArray1 = array(
		    'font'  => array(
		    'bold'  => true,
		    'uppercase' => true,
		    'size'  => 11,
		    'name'  => 'Calibri'
		    )
		);

		$this->excel->getActiveSheet()->getColumnDimension('B')->setWidth(22);
		$this->excel->getActiveSheet()->getColumnDimension('C')->setWidth(40);
		$this->excel->getActiveSheet()->getColumnDimension('D')->setWidth(35);
		$this->excel->getActiveSheet()->getColumnDimension('E')->setWidth(25);
		$this->excel->getActiveSheet()->getColumnDimension('F')->setWidth(25);

		//$this->excel->getActiveSheet()->getStyle('D1:H'.$this->excel->getActiveSheet()->getHighestRow())->getNumberFormat()->setFormatCode('#,##0.00'); 

		$this->excel->getActiveSheet()->getStyle('C1:C'.$this->excel->getActiveSheet()->getHighestRow())
    	->getAlignment()->setWrapText(true);
    	$this->excel->getActiveSheet()->getStyle('K1:K'.$this->excel->getActiveSheet()->getHighestRow())
    	->getAlignment()->setWrapText(true);

		//set aligment to center for that merged cell (A1 to D1)
		// $this->excel->getActiveSheet()->getStyle('B1:B2')->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
		$this->excel->getActiveSheet()->getStyle('B4:B5')->getFont()->setBold(true);

		$filename= 'Laporan Kontrol Sertifikasi Peralatan_'.$date.'.xls'; //save our workbook as this file name
		header('Content-Type: application/vnd.ms-excel'); //mime type
		header('Content-Disposition: attachment;filename="'.$filename.'"'); //tell browser what's the file name
		header('Cache-Control: max-age=0'); //no cache
			             
		//save it to Excel5 format (excel 2003 .XLS file), change this to 'Excel2007' (and adjust the filename extension, also the header mime type)
		//if you want to save it as .XLSX Excel 2007 format
		$objWriter = PHPExcel_IOFactory::createWriter($this->excel, 'Excel5');  
		//force user to download the Excel file without writing it to server's HD
		$objWriter->save('php://output');
	}

	function kontrol_pemakaian_listrik()
	{


		$ls_sql	= " SELECT	*
					FROM	pro_pemakaian_listrik
					WHERE	(UPPER(id_pemakaian) LIKE '%".strtoupper(post('keyword'))."%'
							OR UPPER(no_toko) LIKE '%".strtoupper(post('keyword'))."%'
							OR UPPER(nama_tenant) LIKE '%".strtoupper(post('keyword'))."%'
							OR UPPER(kwh_akhir_meter) LIKE '%".strtoupper(post('keyword'))."%'
							OR UPPER(kwh_akhir_meter) LIKE '%".strtoupper(post('keyword'))."%'
							OR UPPER(kwh_pemakaian) LIKE '%".strtoupper(post('keyword'))."%'
							OR UPPER(lokasi_tempat) LIKE '%".strtoupper(post('keyword'))."%'
							OR UPPER(tanggal) LIKE '%".strtoupper(post('keyword'))."%'
							OR UPPER(jenis_usaha) LIKE '%".strtoupper(post('keyword'))."%') 
							ORDER BY ".(post('sort')=='' ? 'id_pemakaian' : post('sort'))." ".(post('order')=='' ? 'asc' : post('order'));	
	
		$ls_sql2	= "	SELECT COUNT(1)
					FROM	pro_pemakaian_listrik
					WHERE	(UPPER(id_pemakaian) LIKE '%".strtoupper(post('keyword'))."%'
							OR UPPER(no_toko) LIKE '%".strtoupper(post('keyword'))."%'
							OR UPPER(nama_tenant) LIKE '%".strtoupper(post('keyword'))."%'
							OR UPPER(kwh_akhir_meter) LIKE '%".strtoupper(post('keyword'))."%'
							OR UPPER(kwh_akhir_meter) LIKE '%".strtoupper(post('keyword'))."%'
							OR UPPER(kwh_pemakaian) LIKE '%".strtoupper(post('keyword'))."%'
							OR UPPER(lokasi_tempat) LIKE '%".strtoupper(post('keyword'))."%'
							OR UPPER(tanggal) LIKE '%".strtoupper(post('keyword'))."%'
							OR UPPER(jenis_usaha) LIKE '%".strtoupper(post('keyword'))."%') 
							ORDER BY ".(post('sort')=='' ? 'id_pemakaian' : post('sort'))." ".(post('order')=='' ? 'asc' : post('order'));
		
		$total = $this->get_data($ls_sql2);

		$result = $this->db->query($ls_sql);

		$data_p = array(	'rows'=> $result->result_array(), 
								'total' => $total);

		$date = date('Y-m-d');

		//load our new PHPExcel library
		$this->load->library('excel');
		//activate worksheet number 1
		$this->excel->setActiveSheetIndex(0);
		//name the worksheet
		$this->excel->getActiveSheet()->setTitle("Pemakaian Listrik");

		$no = 1;

			
		if ($data_p) {

			$styleArrayBorder = array(
				'borders' => array(
					'allborders' => array(
					'style' => PHPExcel_Style_Border::BORDER_THIN
					)
				)
			);

			$this->excel->getActiveSheet()->setCellValue('B8', 'ID PEMAKAIAN');
			$this->excel->getActiveSheet()->setCellValue('C8', 'NO TOKO');
			$this->excel->getActiveSheet()->setCellValue('D8', 'LOKASI TOKO');
			$this->excel->getActiveSheet()->setCellValue('E8', 'NAMA TENANT');
			$this->excel->getActiveSheet()->setCellValue('F8', 'JENIS USAHA');
			$this->excel->getActiveSheet()->setCellValue('G8', 'KWH AWAL METER');
			$this->excel->getActiveSheet()->setCellValue('H8', 'KWH AKHIR METER');
			$this->excel->getActiveSheet()->setCellValue('I8', 'KWH PEMAKAIAN');
			$this->excel->getActiveSheet()->setCellValue('J8', 'PERIODE PENAGIHAN');
			
			$this->excel->getActiveSheet()->getStyle('B8:J8')->getFont()->setBold(true);
			$this->excel->getActiveSheet()->getStyle('B8:J8')->getFill()->applyFromArray(array('type' => PHPExcel_Style_Fill::FILL_SOLID,'startcolor' => array('rgb' => 'EEEE11')));
			$this->excel->getActiveSheet()->getStyle('B8:J8')->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_CENTER);

			$x = 8;

			for($i=0;$i<=$data_p['total']-1;$i++){
				$x++;

				$rows = $data_p['rows'];
				$rows2 = $rows[$i];


				$this->excel->getActiveSheet()->setCellValue('B'.$x, $rows2['id_pemakaian']);
				$this->excel->getActiveSheet()->setCellValue('C'.$x, $rows2['no_toko']);
				$this->excel->getActiveSheet()->setCellValue('D'.$x, $rows2['lokasi_tempat']);
				$this->excel->getActiveSheet()->setCellValue('E'.$x, $rows2['nama_tenant']);
				$this->excel->getActiveSheet()->setCellValue('F'.$x, $rows2['jenis_usaha']);
				$this->excel->getActiveSheet()->setCellValue('G'.$x, $rows2['kwh_awal_meter']);
				$this->excel->getActiveSheet()->setCellValue('H'.$x, $rows2['kwh_akhir_meter']);
				$this->excel->getActiveSheet()->setCellValue('I'.$x, $rows2['kwh_pemakaian']);
				
				/*$bulan_periode = explode("-", $rows2['tanggal']);
			    if($bulan_periode[0]<='09'){
			      $y1 = substr($bulan_periode[0], 1, 1);

			      $hasil1 = "";
			      $iromawi1 =
			      array("","Januari","Februari","Maret","April","Mei","Juni","Juli","Agustus","September");
			      if(array_key_exists($y1,$iromawi1)){
			        $hasil1 = $iromawi[$y1];
			      }

			      $tgl_new1 = $hasil1." - ".$bulan_periode[1];

			    } else {

			      $hasil1 = "";
			      $iromawi1 =
			      array("","","","","","","","","","","Oktober","November","Desember");
			      if(array_key_exists($bulan_periode[0],$iromawi1)){
			        $hasil1 = $iromawi1[$bulan_periode[0]];
			      }
			      $tgl_new1 = $hasil1." - ".$bulan_periode[1];
			    }*/

				$this->excel->getActiveSheet()->setCellValue('J'.$x, $rows2['tanggal']);
				$no++;
			}
			
		}

		$this->excel->getActiveSheet()->setCellValue('B4', strtoupper("Pemakaian Listrik"));
		$this->excel->getActiveSheet()->setCellValue('B5', '('.$date.')');			

		$styleArray = array(
			'borders' => array(
			    'allborders' => array(
			    'style' => PHPExcel_Style_Border::BORDER_THIN
			    )
			),
			'font'  => array(
			    'size'  => 9,
			    'name'  => 'verdana'
			)
		);

		$this->excel->getActiveSheet()->getStyle('B8:J'.$x)->applyFromArray($styleArray);
		unset($styleArray);

		$styleArray1 = array(
		    'font'  => array(
		    'bold'  => true,
		    'uppercase' => true,
		    'size'  => 11,
		    'name'  => 'Calibri'
		    )
		);

		$this->excel->getActiveSheet()->getColumnDimension('B')->setWidth(22);
		$this->excel->getActiveSheet()->getColumnDimension('C')->setWidth(22);
		$this->excel->getActiveSheet()->getColumnDimension('D')->setWidth(22);
		$this->excel->getActiveSheet()->getColumnDimension('E')->setWidth(35);
		$this->excel->getActiveSheet()->getColumnDimension('F')->setWidth(55);
		$this->excel->getActiveSheet()->getColumnDimension('G')->setWidth(23);
		$this->excel->getActiveSheet()->getColumnDimension('H')->setWidth(23);
		$this->excel->getActiveSheet()->getColumnDimension('I')->setWidth(23);
		$this->excel->getActiveSheet()->getColumnDimension('J')->setWidth(19);


		$this->excel->getActiveSheet()->getStyle('D1:J'.$this->excel->getActiveSheet()->getHighestRow())->getNumberFormat()->setFormatCode('#,##0.00'); 

		$this->excel->getActiveSheet()->getStyle('C1:C'.$this->excel->getActiveSheet()->getHighestRow())
    	->getAlignment()->setWrapText(true);
    	$this->excel->getActiveSheet()->getStyle('J1:J'.$this->excel->getActiveSheet()->getHighestRow())
    	->getAlignment()->setWrapText(true);

		//set aligment to center for that merged cell (A1 to D1)
		// $this->excel->getActiveSheet()->getStyle('B1:B2')->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
		$this->excel->getActiveSheet()->getStyle('B4:B5')->getFont()->setBold(true);

		$filename= 'Pemakaian Listrik'.$date.'.xls'; //save our workbook as this file name
		header('Content-Type: application/vnd.ms-excel'); //mime type
		header('Content-Disposition: attachment;filename="'.$filename.'"'); //tell browser what's the file name
		header('Cache-Control: max-age=0'); //no cache
			             
		//save it to Excel5 format (excel 2003 .XLS file), change this to 'Excel2007' (and adjust the filename extension, also the header mime type)
		//if you want to save it as .XLSX Excel 2007 format
		$objWriter = PHPExcel_IOFactory::createWriter($this->excel, 'Excel5');  
		//force user to download the Excel file without writing it to server's HD
		$objWriter->save('php://output');
	}


	function terbilang_get_valid($str,$from,$to,$min=1,$max=9){
			$val=false;
			$from=($from<0)?0:$from;
			for ($i=$from;$i<$to;$i++){
				if (((int) $str{$i}>=$min)&&((int) $str{$i}<=$max)) $val=true;
			}
			return $val;
	}	

	function terbilang_get_str($i,$str,$len){
			$numA=array("","satu","dua","tiga","empat","lima","enam","tujuh","delapan","sembilan");
     		$numB=array("","se","dua ","tiga ","empat ","lima ","enam ","tujuh ","delapan ","sembilan ");
     		$numC=array("","satu ","dua ","tiga ","empat ","lima ","enam ","tujuh ","delapan ","sembilan ");
      		$numD=array(0=>"puluh",1=>"belas",2=>"ratus",4=>"ribu", 7=>"juta", 10=>"milyar", 13=>"triliun");
			$buf="";
			$pos=$len-$i;
			switch($pos){
				case 1:
						if (!$this->terbilang_get_valid($str,$i-1,$i,1,1))
							$buf=$numA[(int) $str{$i}];
					break;
				case 2:	case 5: case 8: case 11: case 14:
						if ((int) $str{$i}==1){
							if ((int) $str{$i+1}==0)
								$buf=($numB[(int) $str{$i}]).($numD[0]);
							else
								$buf=($numB[(int) $str{$i+1}]).($numD[1]);
						}
						else if ((int) $str{$i}>1){
								$buf=($numB[(int) $str{$i}]).($numD[0]);
						}				
					break;
				case 3: case 6: case 9: case 12: case 15:
						if ((int) $str{$i}>0){
								$buf=($numB[(int) $str{$i}]).($numD[2]);
						}
					break;
				case 4: case 7: case 10: case 13:
						if ($this->terbilang_get_valid($str,$i-2,$i)){
							if (!$this->terbilang_get_valid($str,$i-1,$i,1,1))
								$buf=$numC[(int) $str{$i}].($numD[$pos]);
							else
								$buf=$numD[$pos];
						}						else if((int) $str{$i}>0){
							if ($pos==4)
								$buf=($numB[(int) $str{$i}]).($numD[$pos]);
							else
								$buf=($numC[(int) $str{$i}]).($numD[$pos]);
						}
					break;
			}
			return $buf;
	}
	function toTerbilang($nominal){
			$buf="";
			$str=$nominal."";
			$len=strlen($str);
			
			for ($i=0;$i<$len;$i++){
				$buf=trim($buf)." ".$this->terbilang_get_str($i,$str,$len);
			}
			return trim($buf);
	}
}
?>